1.重定向domain.com到www.domain.com
这种重定向旨在使域名唯一,是网站SEO必须要做的,后面重定向www.domain.com到domain.com也是出于同样的原因,只是形式不同。打开.htaccess文件,加入以下规则。(下面的规则是针对主域名的,子域名要修改)
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 to 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
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^file/file.php$ http://www.otherdomain.com/otherfile/other.php [R=301,L]