【问题标题】:301 redirects for wordpress multisite subdomainswordpress 多站点子域的 301 重定向
【发布时间】:2014-09-24 13:50:50
【问题描述】:

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

我有一个带有子域的 WordPress 多站点安装,我正在尝试让旧 URL 重定向到新 URL。

基本上,我正在使用

RewriteCond %{HTTP_HOST}

以每个子域为目标,后面跟着一批 RewriteRules。

这是我的代码的一个小sn-p:

# 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-de-nous/ . ourclosures.php 重定向也发生了同样的事情。

这段代码我做错了什么?

【问题讨论】:

    标签: wordpress .htaccess mod-rewrite redirect wpmu


    【解决方案1】:

    我在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]
    

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

    【讨论】:

      猜你喜欢
      • 2017-10-20
      • 2021-02-03
      • 2018-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-05
      • 2021-10-24
      • 1970-01-01
      相关资源
      最近更新 更多