2017-02-17 167 views
1

我有问题,子域重定向。htaccess从子域重定向

当前重定向:

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重定向之前写过

回答

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] 
+0

非常感谢,所以不可能为一个RewriteCond使用多个rewriterules? – Nefro

+0

是的,这是可能的。我更新了答案 –

+0

,但我有50多个重写过滤器,并且重定向页面有时与旧的不匹配 – Nefro