htaccess从子域重定向

时间:2017-02-17 21:03:17

标签: wordpress apache .htaccess redirect

我遇到子域重定向问题。

当前重定向:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub.website.com$
RewriteRule ^any/other/page/$ http://website.com/sub/any/other/page/ [R=301,L,NC,QSA]
RewriteRule ^blog/$ http://website.com/sub/blog/ [R=301,L,NC,QSA]
..... and much more other rewriterule (50+)

从子域重定向工作正常,但http://website.com/blog/也重定向到http://website.com/sub/blog/

也许有人能找到问题?

P.S。使用wordpress,我的重定向在wordpress重定向之前写了

1 个答案:

答案 0 :(得分:2)

您有1个条件和2个规则。条件仅适用于最后一个条件后的第一个重写。你需要另外一个与你使用它们的方式。

RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub\.website\.com$
RewriteRule ^any/other/page/$ http://website.com/sub/any/other/page/ [R=301,L,NC,QSA]
RewriteCond %{HTTP_HOST} ^sub\.website\.com$
RewriteRule ^blog/$ http://website.com/sub/blog/ [R=301,L,NC,QSA]

根据您的评论。

如果你想巩固你可以做到这一点。

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^sub\.website\.com$
    RewriteRule ^(any/other/page|blog)/$ http://website.com/sub/$1/ [R=301,L,NC,QSA]