網(wǎng)站建設如何做301重定向發(fā)布者:本站 時(shí)間:2020-03-19 16:03:43
在網(wǎng)站運營(yíng)的過(guò)程中,有時(shí)因一些不同的訪(fǎng)問(wèn)要求(譬如使用http://1.abc.com訪(fǎng)問(wèn)的是http://www.abc.com/1,使用http://2.abc.com訪(fǎng)問(wèn)的是http://www.abc.com/2),需對網(wǎng)站訪(fǎng)問(wèn)進(jìn)行重定向設置。在我司的平臺上,最直接最有效的做法是通過(guò)URL重寫(xiě)規則實(shí)現。下面給出URL重寫(xiě)實(shí)現重定向的的一些常用范例。
注意:在設置301重定向之前務(wù)必備份相應目錄下的.htaccess文件。(Windows主機是在/htdocs目錄下,Linux主機是在根目錄下)
1.重定向domain.com到www.domain.com
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
2.重定向www.domain.com到domain.com
RewriteEngine On
RewriteCond %{HTTP_HOST} !^domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
3.重定向olddomain.com到www.newdomain.com
RewriteEngine On
RewriteCond %{HTTP_HOST} !olddomain.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]
4.重定向olddomain.com 到 newdomain.com
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !olddomain.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]
5.重定向domain.com/file/file.php 到 otherdomain.com/otherfile/other.php
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^file/file.php$ http://www.otherdomain.com/otherfile/other.php [R=301,L]
選擇我們,優(yōu)質(zhì)服務(wù),不容錯過(guò)
1. 優(yōu)秀的網(wǎng)絡(luò )資源,強大的網(wǎng)站優(yōu)化技術(shù),穩定的網(wǎng)站和速度保證
2. 15年上海網(wǎng)站建設經(jīng)驗,優(yōu)秀的技術(shù)和設計水平,更放心
3. 全程省心服務(wù),不必擔心自己不懂網(wǎng)絡(luò ),更省心。
------------------------------------------------------------
24小時(shí)聯(lián)系電話(huà):021-58370032