1

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

2 回答 2

1

Your current rules seem to be faulty since RewriteCond only applies to very next RewriteRule. With the new rule have your complete .htaccess like this:

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]
于 2013-11-10T07:15:10.243 回答
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来适当地映射。

于 2013-11-09T20:12:54.147 回答