Internet信息服務管理器 -> 虛擬目錄 -> 重定向到URL,輸入需要轉向的目標URL,並選擇“資源的永久重定向”。
<%@ %>
< %
Response.Status=”301 Moved Permanently”
Response.AddHeader “Location”, “http://www.sem.cm/articles/301/”
%>
<script runat=”server”>
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = “301 Moved Permanently”;
Response.AddHeader(”Location”,”http://www.sem.cm/articles/301/“);
}
< /script>
header(”HTTP/1.1 301 Moved Permanently”);
header(”Location: http://www.sem.cm/articles/301/”);
exit();
$q = new CGI;
print $q->redirect(”http://www.sem.cm/”);
<%
response.setStatus(301);
response.setHeader( “Location”, “http://www.sem.cm/” );
response.setHeader( “Connection”, “close” );
%>
新建.htaccess文件,輸入下列內容(需要開啟mod_rewrite):
1)將不帶WWW的域名轉向到帶WWW的域名下
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^semshare.net [NC]
RewriteRule ^(.*)$ http://www.sem.cm/$1 [L,R=301]
2)重定向到新域名
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://www.sem.cm/$1 [L,R=301]
3)使用正則進行301轉向,實現偽靜態
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news-(.+).html$ news.php?id=$1
將news.php?id=123這樣的地址轉向到news-123.html
為實現URL規范化,SEO通常將不帶WWW的域名轉向到帶WWW域名,vhosts.conf中配置為:
<VirtualHost *:80>
ServerName www.sem.cm
DocumentRoot /home/semshare
< /VirtualHost>
<VirtualHost *:80>
ServerName semshare.net
RedirectMatch permanent ^/(.*) http://www.sem.cm/$1
< /VirtualHost>
另外部分服務器IDC會提供自定義301等面板,根據具體實際情況來應用哈。
測試一下你的跳轉是否成功,提供2個301轉向情況檢測工具:
http://www.seoconsultants.com/tools/headers.asp
http://www.internetofficer.com/seo-tool/redirect-check/