.htaccess文件URL重写规则实现301重定向

一、重定向domain.com到www.domain.com

RewriteEngine On

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

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

二、重定向www.domain.com到domain.com

RewriteEngine On

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

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

三、重定向旧域名olddomain.com到新域名www.newdomain.com

RewriteEngine On

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

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

四、重定向旧域名olddomain.com 到新域名newdomain.com

RewriteEngine On

 RewriteBase /

 RewriteCond %{HTTP_HOST} ^olddomain.com$ [NC]

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

五、重定向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]

今天就写到这,欢迎大家指正完善,谢谢!

你可能感兴趣的:(.htaccess文件URL重写规则实现301重定向)