301重定向到所有页面

时间:2013-11-09 20:08:06

标签: .htaccess

我想用搜索查询进行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]

2 个答案:

答案 0 :(得分: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]

答案 1 :(得分:0)

假设域之间的目录结构保持不变,您可以通过以下方式执行此操作:

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

如果目录结构DID发生变化,您可以在NEW域的.htaccess文件上使用其他规则进行适当的映射。