301轉(zhuǎn)向代碼大合集(jí) 包括IIS、apache和(hé)PHP程序/asp程序的301轉向設(shè)置(zhì)
綠色資源網將SEO工(gōng)作中所(suǒ)需要的301轉向代(dài)碼,包括程序上(php、asp)和Web服務器(apache、iis)下設置都進行了整理,收藏並分享,以(yǐ)備(bèi)查閱。
1、IIS下301設置
Internet信息服務管理器 -> 虛擬目錄 -> 重定向到URL,輸(shū)入(rù)需(xū)要(yào)轉向的目標URL,並選擇“資源的永久重定向”。
2、ASP下的301轉向代碼
<%@ Language=VBScript %>
<%
Response.Status=”301 Moved Permanently”
Response.AddHeader “locations”, “http://www.ynaad.com/”
%>
3、ASP.Net下的301轉向代碼
<script runat=”server”>
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = “301 Moved Permanently”;
Response.AddHeader(”locations”,”http://www.ynaad.com/“);
}
</script>
4、PHP下的301轉向代碼
header(”HTTP/1.1 301 Moved Permanently”);
header(”locations: http://www.ynaad.com/”);
exit();
5、CGI Perl下的(de)301轉向(xiàng)代碼
$q = new CGI;
print $q->redirect(”http://www.ynaad.com/”);
6、JSP下的301轉向代碼
<%
response.setStatus(301);
response.setHeader( “locations”, “http://www.ynaad.com/” );
response.setHeader( “Connection”, “close” );
%>
7、Apache下301轉向代碼
新建.htaccess文件,輸入下(xià)列內容(需要開啟mod_rewrite):
1)將(jiāng)不(bú)帶(dài)WWW的域名轉向到帶WWW的域名下(xià)
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ynaad.com [NC]
RewriteRule ^(.*)$ http://www.ynaad.com/$1 [L,R=301]
2)重定向(xiàng)到新域名
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://www.ynaad.com/$1 [L,R=301]
3)使用正(zhèng)則進行(háng)301轉向,實現偽靜態
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news-(.+)\.html$ news.php?id=$1
將news.php?id=123這(zhè)樣的地址轉向到news-123.html
8、Apache下vhosts.conf中配置(zhì)301轉向
為實現URL規範化,SEO通常(cháng)將不帶WWW的域名轉向到帶WWW域名,vhosts.conf中配置為:
<VirtualHost *:80>
ServerName www.ynaad.com
DocumentRoot /home/itokit
</VirtualHost>
<VirtualHost *:80>
ServerName ynaad.com
RedirectMatch permanent ^/(.*) http://www.ynaad.com/$1
</VirtualHost>
Apache下除了以上2種方(fāng)法,還(hái)有其他配置(zhì)方法和可(kě)選參數,建議閱讀Apache文(wén)檔。
301轉(zhuǎn)向情況檢測
關鍵詞:301轉向,IIS,apache,PHP,asp
閱讀本文後(hòu)您有什麽感想? 已有 人給出評(píng)價!
- 3
- 3
- 3
- 3
- 2
- 1