因為LosesToy用的是合租伺服器,所以這裡沒有涉及到透過IIS或Apache設定301重定向的方法
1、ASP下的301轉向代碼
<%@ Language=VBScript %>
<%
Response.Status=”301 Moved Permanently”
Response.AddHeader “Location”, “http://www.lesishu.cn/articles/301/”
%>
3.ASP.Net下的301轉向程式碼
<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轉向代碼
header(”HTTP/1.1 301 Moved Permanently”);
header(”Location: http://www.lesishu.cn/articles/301/ ”);
exit();
5、CGI Perl下的301轉向代碼
$q = new CGI;
print $q->redirect(”http://www.new-url.com/”);
6.JSP下的301轉向代碼
<%
response.setStatus(301);
response.setHeader( “Location”, “http://www.lesishu.cn/” );
response.setHeader( “Connection”, “close” );
%>
7、Apache下301轉向代碼
新建.htaccess文件,輸入下列內容(需要開啟mod_rewrite):
1)將不帶WWW的域名轉向到帶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)使用正規進行301轉向,實現偽靜態
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news-(.+).html$ news.php?id=$1
將news.php?id=123這樣的位址轉向news-123.html