博主呓语:

.htaccess实现301重定向规则总汇

Posted by 破冰 on 2012-9-14 18:05 Friday

1.重定向xshell.net到www.xshell.net
这种重定向旨在使域名唯一,是网站SEO必须要做的,后面重定向www.xshell.net到xshell.net也是出于同样的原因,只是形式不同。
打开.htaccess文件,加入以下规则。(下面的规则是针对主域名的,子域名要修改)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^xshell.net$ [NC]
RewriteRule ^(.*)$ http://www.xshell.net/$1 [L,R=301]


2.重定向www.xshell.net到xshell.net

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.xshell.net$ [NC]
RewriteRule ^(.*)$ http://xshell.net/$1 [L,R=301]


3.重定向oldxshell.net到www.newxshell.net

RewriteEngine On
RewriteCond %{HTTP_HOST} !oldxshell.net$ [NC]
RewriteRule ^(.*)$ http://www.newxshell.net/$1 [L,R=301]


4.重定向oldxshell.net to newxshell.net

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !oldxshell.net$ [NC]
RewriteRule ^(.*)$ http://newxshell.net/$1 [L,R=301]


5.重定向xshell.net/file/file.php 到 otherxshell.net/otherfile/other.php

RewriteCond %{HTTP_HOST} ^www.xshell.net$
RewriteRule ^file/file.php$ http://www.otherdomain.com/otherfile/other.php [R=301,L]

 

发表评论: