利用IIS目錄改版實現(xiàn)301轉(zhuǎn)向(全站重定向)
廣告:
1. 利用程序跳轉(zhuǎn)
asp.net 3.1
#region 301轉(zhuǎn)向
public static void To301(string path)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.StatusCode = 301;
HttpContext.Current.Response.AppendHeader("location", path);
HttpContext.Current.Response.End();
}
#endregion
asp 301
<%@ Language=VBScript %>
<%
Response.Status=”301 Moved Permanently”
Response.AddHeader “Location”, “http://www.****.cn/articles/301/”
%>
php 301
header(”HTTP/1.1 301 Moved Permanently”);
header(”Location: http://www.****.cn/articles/301/”);
exit();
jsp 301
<%
response.setStatus(301);
response.setHeader( “Location”, “http://www.****.cn/” );
response.setHeader( “Connection”, “close” );
%>
2. 利用服務(wù)器iis實現(xiàn)轉(zhuǎn)向
iis,在要轉(zhuǎn)向的目錄(原目錄不要刪)右鍵,屬性-重定向到url,如:加$s$q參數(shù)
http://demo.53bk.com/shouji$S$Q (注意:S和Q一定要大寫,不然不生效)
上面準確的url和資源永久重定向打勾。
3. IIs8.5和iis 7.5 :
要建一個目錄:里面web.cofig
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="true" destination="http://zaoyuan.ysneo.com$S$Q" exactDestination="true" httpResponseStatus="Permanent" />
</system.webServer>
</configuration>
http重定向---將請求重定向到此目標---http://www.jdki.com.cn$S$Q (將所有請求重定向到確切的目標(而不是相對于目標)打勾,狀態(tài)代碼設(shè)為永久( 301))
4、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.****.cn/$1 [L,R=301]
2)重定向到新域名
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://www.****.cn/$1 [L,R=301]
3)使用正則進行301轉(zhuǎn)向,實現(xiàn)偽靜態(tài)
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news-(.+)\.html$ news.php?id=$1
將news.php?id=123這樣的地址轉(zhuǎn)向到news-123.html
5、Apache下vhosts.conf中配置301轉(zhuǎn)向
為實現(xiàn)URL規(guī)范化,SEO通常將不帶WWW的域名轉(zhuǎn)向到帶WWW域名,vhosts.conf中配置為:
<VirtualHost *:80>
ServerName www.****.cn
DocumentRoot /home/lesishu
</VirtualHost>
<VirtualHost *:80>
ServerName lesishu.cn
RedirectMatch permanent ^/(.*) http://www.****.cn/$1
</VirtualHost>
廣告: