301轉(zhuǎn)向代碼合集

2022-07-07    分類: 網(wǎng)站建設(shè)

樂思蜀將SEO工作中所需要的301轉(zhuǎn)向代碼進(jìn)行了整理,收藏并分享,以備查閱。

1、IIS下301設(shè)置

Internet信息服務(wù)管理器 -> 虛擬目錄 -> 重定向到URL,輸入需要轉(zhuǎn)向的目標(biāo)URL,并選擇“資源的永久重定向”。

2、ASp下的301轉(zhuǎn)向代碼

<%@ Language=VBScript %>

<%

Response.Status=”301 Moved permanently”

Response.AddHeader “Location”, “http://www.lesishu.cn/articles/301/”

%>

3、ASp.Net下的301轉(zhuǎn)向代碼

<script runat=”server”>

private void page_Load(object sender, System.EventArgs e)

{

Response.Status = “301 Moved permanently”;

Response.AddHeader(”Location”,”http://www.lesishu.cn/articles/301/“);

}

</script>

4、pHp下的301轉(zhuǎn)向代碼

header(”HTTp/1.1 301 Moved permanently”);

header(”Location: http://www.lesishu.cn/articles/301/”);

exit();

5、CGI perl下的301轉(zhuǎn)向代碼

$q = new CGI;

print $q->redirect(”http://www.new-url.com/”);

6、JSp下的301轉(zhuǎn)向代碼

<%

response.setStatus(301);

response.setHeader( “Location”, “http://www.lesishu.cn/” );

response.setHeader( “Connection”, “close” );

%>

7、Apache下301轉(zhuǎn)向代碼

新建.htaccess文件,輸入下列內(nèi)容(需要開啟mod_rewrite):

1)將不帶WWW的域名轉(zhuǎn)向到帶WWW的域名下

Options +FollowSymLinks

RewriteEngine on

RewriteCond %{HTTp_HOST} ^lesishu.cn [NC]

RewriteRule ^(.*)$ http://www.lesishu.cn/$1 [L,R=301]

2)重定向到新域名

Options +FollowSymLinks

RewriteEngine on

RewriteRule ^(.*)$ http://www.lesishu.cn/$1 [L,R=301]

3)使用正則進(jìn)行301轉(zhuǎn)向,實(shí)現(xiàn)偽靜態(tài)

Options +FollowSymLinks

RewriteEngine on

RewriteRule ^news-(.+).html$ news.php?id=$1

將news.php?id=123這樣的地址轉(zhuǎn)向到news-123.html

8、Apache下vhosts.conf中配置301轉(zhuǎn)向

為實(shí)現(xiàn)URL規(guī)范化,SEO通常將不帶WWW的域名轉(zhuǎn)向到帶WWW域名,vhosts.conf中配置為:

<VirtualHost *:80>

ServerName www.lesishu.cn

DocumentRoot /home/lesishu

< irtualHost>

<VirtualHost *:80>

ServerName lesishu.cn

RedirectMatch permanent ^/(.*) http://www.lesishu.cn/$1

< irtualHost>

Apache下除了以上2種方法,還有其他配置方法和可選參數(shù),建議閱讀Apache文檔。

301轉(zhuǎn)向情況檢測(cè)

http://www.seoconsultants.com/tools/headers.asp

http://www.internetofficer.com/seo-tool/redirect-check/

新聞標(biāo)題:301轉(zhuǎn)向代碼合集
鏈接URL:http://www.muchs.cn/news21/175471.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、網(wǎng)站設(shè)計(jì)公司、服務(wù)器托管網(wǎng)站維護(hù)、全網(wǎng)營(yíng)銷推廣、企業(yè)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名