301重定向的方法有:
1、IIS下301設置
Internet信息服務管理器 → 虛擬目錄 → 重定向到URL,輸入需要轉向的目標URL,并選擇“資源的永久重定向”。
2、ASP下的301重定向代碼
<%@ Language=VBScript %>
<%
if request.ServerVariables("SERVER_NAME")="blog.yisu.com" or
request.ServerVariables("SERVER_NAME")="yisu.com" then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://kemok4.com/"
Response.End
end if
%>
3、ASP.Net下的301重定向代碼
<script runat=”server”>
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = “301 Moved Permanently”;
Response.AddHeader(”Location”,”kemok4.com/301/“);
}
</script>
4、PHP下的301重定向代碼
if(($HTTP_SERVER_VARS["HTTP_HOST"]=="blog.yisu.com")||($HTTP_SERVER_VARS
["HTTP_HOST"]=="seotest.com"))
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://kemok4.com/");
}
5、CGI Perl下的301重定向代碼
$q = new CGI;
print $q->redirect(”kemok4.com/301/”);
6、JSP下的301重定向代碼
<%
response.setStatus(301);
response.setHeader( “Location”, “kemok4.com/301/ );
response.setHeader( “Connection”, “close” );
%>
7、Apache下301重定向代碼
新建.htaccess文件,輸入下列內容(需要開啟mod_rewrite):
1)將不帶WWW的域名轉向到帶WWW的域名下
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yisu.com [NC]
RewriteRule ^(.*)$kemok4.com/301/[L,R=301]
2)重定向到新域名
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$wkemok4.com/301/ [L,R=301]
3)使用正則進行301重定向,實現(xiàn)偽靜態(tài)
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news-(.+)\.html$ news.php?id=$1
將news.php?id=123這樣的地址轉向到news-123.html
8、Apache下vhosts.conf中配置301重定向
為實現(xiàn)URL規(guī)范化,SEO通常將不帶WWW的域名轉向到帶WWW域名,vhosts.conf中配置如下:
<VirtualHost *:80>
ServerName kemok4.com/
DocumentRoot /home/yisu
</VirtualHost>
<VirtualHost *:80>
ServerName seotest.com
RedirectMatch permanent ^/(.*) kemok4.com/301/
</VirtualHost>
9.讓zblog不帶www的域名重定向到www的方法
打開博客根目錄default.asp,在<!--#include file="class/cls_logAction.asp" -->一行下面添加一下代碼即可。
<%
if request.ServerVariables("SERVER_NAME")="yisu.com" then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://kemok4.com/"
Response.End
end if
%>