Apache的各種重定向?qū)嵗?/h1>
1.訪問網(wǎng)站某目錄301重定向另外一個(gè)域名ServerName www.iknowing.comServerAlias iknowing.comDocumentRoot "f:/Apache2.2/h
1.訪問網(wǎng)站某目錄301重定向另外一個(gè)域名
ServerName www.iknowing.com
ServerAlias iknowing.com
DocumentRoot "f:/Apache2.2/htdocs/aa"
#將目錄shsx下內(nèi)容301重定向www.shanghaishuxie.cn
Redirect permanent /shsx http://www.shanghaishuxie.cn/
上面例子就是:
將訪問www.iknowing.com/shsx 內(nèi)容301重定向到www.shanghaishuxie.cn
2.訪問某個(gè)域名重定向到另外一個(gè)域名的某個(gè)目錄
ServerName lj.abc.cn
#DocumentRoot "C:/Apache2.2/htdocs/htdocs2/aa"
RedirectMatch 301 ^(.*) http://www.cde/lj/
將lj.iknowing.cn 所有請(qǐng)求都重定向到 http://www.cde.cn/lj/
3.訪問某個(gè)域名讓瀏覽器自動(dòng)跳轉(zhuǎn)到該域名下的某個(gè)目錄,不顯示首頁
比如 訪問 www.abc.cn 直接定位到 www.abc.cn/lll
ServerName www.abc.cn
RedirectMatch ^/$ http://www.abc.cn/lll
4.將域名A下的頁面全部301重定向到域名B去,當(dāng)網(wǎng)站要換域名的時(shí)候用到。
ServerName zazhi.sitebao.net
Redirect permanent / http://zazhi.wingsmedia.com.cn/
RedirectMatch (.*).html$ http://zazhi.wingsmedia.com.cn/
3 、4行還可以這樣
RewriteEngine ON
RewriteRule ^(.*)$ http://zazhi.wingsmedia.com.cn/$1 [R=301,L]
5.訪問首頁index.shtml跳轉(zhuǎn)到域名根下。一般用于SEO優(yōu)化,防止首頁權(quán)重分散。
比如訪問 www.sitebao.com/index.shtml 跳轉(zhuǎn)到 www.sitebao.com
rewriteEngine on
rewriteRule /index.shtml http://www.sitebao.com/ [R=permanent,L]
6.輸入域名自動(dòng)跳轉(zhuǎn)到該網(wǎng)站下的某頁面,常用于某個(gè)重要的產(chǎn)品或事件頁面宣傳,大公司的網(wǎng)站進(jìn)經(jīng)常這樣做。
ServerName farm.oasiseco.org
ServerAlias farm.oasiseco.org
RedirectMatch ^/$ http://farm.oasiseco.org/104.shtml
輸入farm.oasiseco.org 就跳轉(zhuǎn)到 http://farm.oasiseco.org/104.shtml ,不顯示再首頁,直接顯示104.shtml頁面內(nèi)容。
7.訪問域名下某個(gè)頁面跳轉(zhuǎn)到同域名下另外的一個(gè)頁面
如訪問www.ipudong.net/main.html 跳轉(zhuǎn)到http://www.ipudong.net/index.shtml
在虛擬主機(jī)中增加配置如下
Redirect permanent /main.html http://www.ipudong.net/index.shtml