閱讀200 返回首頁    go 阿裏雲 go 技術社區[雲棲]


各種語言版本的301轉向代碼的寫法

一: IIS中實現301轉向:
1.打開internet信息服務管理器,在欲重定向的網頁或目錄上按右鍵
2.選中“重定向到URL”
3.在對話框中輸入目標頁麵的地址
4.選中“資源的永久重定向”
5.點擊“應用”即可生效
二:ASP下的301轉向代碼:
ASP下的301轉向代碼:
<%@ Language="VBScript" %>
<%
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", "https://www.0701yt.net"
%>


代碼使用方法可參見本人以前寫的關於301永久重定向的文章.
三:PHP下的301轉向代碼:
PHP下的301轉向代碼:
<?
header("HTTP/1.1 301 Moved Permanently");
header("Location:https://www.0701yt.net");
exit();
?>


四:ASP.Net下的301轉向代碼:
ASP.Net下的301轉向代碼:
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","https://www.0701yt.net");
}
</script>


五:CGI Perl下的301轉向代碼:
CGI Perl下的301轉向代碼:
$q = new CGI;
print $q->redirect("https://www.0701yt.net");


六:JSP下的301轉向代碼:
JSP下的301轉向代碼:
<%
response.setStatus(301);
response.setHeader( "Location", "https://www.0701yt.net" );
response.setHeader( "Connection", "close" );
%>


七:Apache下301轉向代碼:
新建.htaccess文件,輸入下列內容(需要開啟mod_rewrite):
1)將不帶WWW的域名轉向到帶WWW的域名下:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^lesishu.cn [NC]
RewriteRule ^(.*)$ https://www.0701yt.net/$1 [L,R=301]


2)重定向到新域名:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ https://www.0701yt.net/$1 [L,R=301]


八:Apache下vhosts.conf中配置301轉向:
為實現URL規範化,SEO通常將不帶WWW的域名轉向到帶WWW域名,vhosts.conf中配置為:
Apache下vhosts.conf中配置301轉向:
<VirtualHost *:80>
ServerName www.mf591.com
DocumentRoot /home/lesishu
</VirtualHost>
<VirtualHost *:80>
ServerName mf591.com
RedirectMatch permanent ^/(.*) https://www.0701yt.net/$1
</VirtualHost>


九:Ruby中實現301轉向:
Ruby中實現301轉向:
def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to "https://www.0701yt.net"
end


十:Coldfusion中實現301轉向:
Coldfusion中實現301轉向:
<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="https://www.0701yt.net">


附:301轉向情況檢測地址
https://www.internetofficer.com/seo-tool/redirect-check/
輸入你的url點:"Check Redirects"
若出現以下內容則301永久轉向成功:

最後更新:2017-04-02 04:00:24

  上一篇:go 文件對話框的使用
  下一篇:go C#中的參數傳遞