1、IIS下301設置
Internet信息服務管理器 -> 虛擬目錄 -> 重定向到URL,輸入需要轉向的目標URL,并選擇“資源的永久重定向”。
在IIS中,也可以通過安裝ISAPI Rewrite組件來實現如Apache中mod_rewrite的功能,詳見ISAPI Rewrite 3下載及常用301規(guī)則。
2、ASP下的301重定向代碼
%@ Language=VBScript %>
%
Response.Status=”301 Moved Permanently”
Response.AddHeader “Location”, “106/”
%>
3、ASP.Net下的301重定向代碼
script runat=”server”>
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = “301 Moved Permanently”;
Response.AddHeader(”Location”,” 106/“);
}
/script>
4、PHP下的301重定向代碼
header(”HTTP/1.1 301 Moved Permanently”);
header(”Location: 106/”);
exit();
5、CGI Perl下的301重定向代碼
$q = new CGI;
print $q->redirect(””);
6、JSP下的301重定向代碼
%
response.setStatus(301);
response.setHeader( “Location”, “” );
response.setHeader( “Connection”, “close” );
%>
7、Apache下301重定向代碼
新建.htaccess文件,輸入下列內容(需要開啟mod_rewrite):
1)將不帶WWW的域名轉向到帶WWW的域名下
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^embeta.com [NC]
RewriteRule ^(.*)$ $1 [L,R=301]
2)重定向到新域名
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ $1 [L,R=301]
3)使用正則進行301轉向,實現偽靜態(tài)
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news-(.+)\.html1
將news.php?id=123這樣的地址轉向到news-123.html
8、Apache下vhosts.conf中配置301重定向
為實現URL規(guī)范化,SEO通常將不帶WWW的域名轉向到帶WWW域名,vhosts.conf中配置為:
VirtualHost *:80>
ServerName DocumentRoot /home/embeta
/VirtualHost>
VirtualHost *:80>
ServerName embeta.com
RedirectMatch permanent ^/(.*) $1
/VirtualHost>
Apache下除了以上2種方法,還有其他配置方法和可選參數,建議閱讀Apache文檔。
標簽:巴彥淖爾 宜賓 內蒙古 96 山南 防城港 日照 定州
巨人網絡通訊聲明:本文標題《301重定向代碼合集(iis,asp,php,asp.net,apache)》,本文關鍵詞 301,重定向,代碼,合集,iis,;如發(fā)現本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網絡,涉及言論、版權與本站無關。