2013-11-09 218 views
1

我想用搜索查询执行301重定向。301重定向到所有页面

例如:abc.com应该重定向到abc.org ,如果有人想给abc.com/xyz.html进入,然后还必须重定向到abc.org/xyz.html

下面

是目前的htaccess部分。

RewriteRule pages/(.*) single.php?page=$1 [L,QSA] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteRule ^rss.xml$ rss.php [L] 
RewriteRule (.*)\.html song.php?q=$1 [L,QSA] 

回答

1

由于RewriteCond仅适用于接下来的RewriteRule,您目前的规则似乎有缺陷。随着新规则有你的完整.htaccess是这样的:

RewriteEngine On 

RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC] 
RewriteRule^http://www.newdomain.com%{REQUEST_URI} [ [R=301,L,NE] 

RewriteRule ^pages/(.*)$ single.php?page=$1 [L,QSA,NC] 

RewriteRule ^rss\.xml$ rss.php [L,NC] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteRule ^([^.]+)\.html$ song.php?q=$1 [L,QSA,NC] 
0

假设目录结构呆在域之间是相同的,你可以通过做以下几点:

RewriteEngine On 
    RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR] 
    RewriteCond %{HTTP_HOST} ^www.olddomain.com$ 
    RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L] 

如果目录结构的确发生了变化,你可以在新领域的.htaccess使用附加规则文件来适当映射。