通过URL重写规则语句实现301重定向

来源:本站发布时间:2012-01-27浏览次数:471次

通过URL重写规则语句实现301重定向

 

在网站运营的过程中,有时因一些不同的访问要求(譬如使用http://1.uwill.com.cn访问的是http://www.uwill.com.cn/1,使用http://2.uwill.com.cn访问的是http://www.uwill.com.cn/2),需对网站访问进行重定向设置。最直接最有效的做法是通过URL重写规则实现。下面给出URL重写实现重定向的的一些常用范例。

注意:在设置301重定向之前务必备份相应目录下的.htaccess文件。(Windows主机是在/htdocs目录下,Linux主机是在根目录下)

1.重定向uwill.com.cn到www.uwill.com.cn

RewriteEngine On

 RewriteCond %{HTTP_HOST} !^www.uwill.com.cn$ [NC]

 RewriteRule ^(.*)$ http://www.uwill.com.cn/$1 [L,R=301]

 

2.重定向www.uwill.com.cn到uwill.com.cn

RewriteEngine On

 RewriteCond %{HTTP_HOST} !^uwill.com.cn$ [NC]

 RewriteRule ^(.*)$ http://uwill.com.cn/$1 [L,R=301]

 

3.重定向olduwill.com.cn到www.newuwill.com.cn

RewriteEngine On

 RewriteCond %{HTTP_HOST} !olduwill.com.cn$ [NC]

 RewriteRule ^(.*)$ http://www.newuwill.com.cn/$1 [L,R=301]

 

4.重定向olduwill.com.cn 到 newuwill.com.cn

RewriteEngine On

 RewriteBase /

 RewriteCond %{HTTP_HOST} !olduwill.com.cn$ [NC]

 RewriteRule ^(.*)$ http://newuwill.com.cn/$1 [L,R=301]

 

5.重定向uwill.com.cn/file/file.php 到 otheruwill.com.cn/otherfile/other.php

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www.uwill.com.cn$

 RewriteRule ^file/file.php$ http://www.otheruwill.com.cn/otherfile/other.php [R=301,L] 

在线咨询

点击这里给我发消息 售前咨询专员

点击这里给我发消息 售后服务专员

在线咨询

24小时服务热线

18927550992
18927550992

免费通话

微信扫一扫

微信联系
返回顶部