从旧域重定向到新域不起作用

时间:2015-04-08 18:48:51

标签: php wordpress apache .htaccess mod-rewrite

我尝试从旧域重定向到新域,通过以下代码,但无法正常工作,错误在哪里。

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$
RewriteRule ^/?$ "http\:\/\/mydomain\.com\/" [R=301,L]
</IfModule>

# END WordPress

1 个答案:

答案 0 :(得分:2)

您需要在WP catch-all规则之前放置重定向规则,否则您只能在重定向新域后获得index.php

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

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

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>