我遇到了一个与这里描述的问题非常相似的问题,但从未得到解决。
我安装了一个带有子域的WordPress多站点,我正在尝试将旧的URL重定向到新的URL。
基本上,我使用
RewriteCond %{HTTP_HOST}
以每个子域为目标,随后会有一批RewriteRules。
以下是我的代码的一小段:
# Rewrite rules for French site
RewriteCond %{HTTP_HOST} ^fr.nomacorc.com$ [nc]
RewriteRule ^home.php$ http://fr.nomacorc.com/ [R=301,NC,L]
RewriteRule ^aboutus.php$ http://fr.nomacorc.com/propos-de-nous/ [R=301,NC,L]
RewriteRule ^ourclosures.php$ http://fr.nomacorc.com/bouchons-pour-le-vin/ [R=301,NC,L]
# Rewrite rules for German site
RewriteCond %{HTTP_HOST} ^de.nomacorc.com$ [nc]
RewriteRule ^home.php$ http://de.nomacorc.com/ [R=301,NC,L]
RewriteRule ^aboutus.php$ http://de.nomacorc.com/uber-uns/ [R=301,NC,L]
RewriteRule ^ourclosures.php$ http://de.nomacorc.com/weinverschlusse/ [R=301,NC,L]
我想让de.nomacorc.com/aboutus.php重定向到de.nomacorc.com/uber-uns,但它重定向到fr.nomacorc.com/propose-de-nous/。ourclosures.php重定向也发生了同样的事情。
我用这个代码做错了什么?
我在另一个线程上找到了答案。
我需要做的是将RewriteRules组链接到上面的RewriteCond。做到这一点的方法描述得很好:
- Negate the condition (prepend it with !) - If you have multiple RewriteConds: - Change logical ANDs in the Conds to ORs and vice versa. - Add a skipping rewrite rule in front of all rules that you want to tie to the condition(s), set the S parameter to the number of Rule lines to be skipped.
这是我更正的代码:
# Rewrite rules for French site
RewriteCond %{HTTP_HOST} !^fr.nomacorc.com$ [nc]
RewriteRule .? - [S=3]
RewriteRule ^home.php$ http://fr.nomacorc.com/ [R=301,NC,L]
RewriteRule ^aboutus.php$ http://fr.nomacorc.com/propos-de-nous/ [R=301,NC,L]
RewriteRule ^ourclosures.php$ http://fr.nomacorc.com/bouchons-pour-le-vin/ [R=301,NC,L]
# Rewrite rules for German site
RewriteCond %{HTTP_HOST} !^de.nomacorc.com$ [nc]
RewriteRule .? - [S=3]
RewriteRule ^home.php$ http://de.nomacorc.com/ [R=301,NC,L]
RewriteRule ^aboutus.php$ http://de.nomacorc.com/uber-uns/ [R=301,NC,L]
RewriteRule ^ourclosures.php$ http://de.nomacorc.com/weinverschlusse/ [R=301,NC,L]
我希望这能帮助到其他可能有同样问题的人!