301重定向用于wordpress多站点子域

时间:2014-09-24 13:50:50

标签: wordpress .htaccess mod-rewrite redirect wpmu

我遇到的问题与here描述的问题非常相似,但从未解决。

我有一个包含子域名的WordPress多站点安装,我试图让旧网址重定向到新网址。

基本上,我正在使用

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/propos-去理性/。使用ourclosures.php重定向也是如此。

这段代码我做错了什么?

1 个答案:

答案 0 :(得分:3)

我在this other thread找到了答案。

我需要做的是将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]

我希望这可以帮助其他可能遇到同样问题的人!