Nefro
Nefro

Reputation: 185

htaccess redirect from subdomain

I have problem with subdomain redirects.

Current redirects:

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+)

redirect from subdomain work fine, but http://website.com/blog/ is also redirect to http://website.com/sub/blog/

Maybe someone can find the problem ?

P.S. using on wordpress, my redirect writed before wordpress redirects

Upvotes: 1

Views: 62

Answers (1)

Panama Jack
Panama Jack

Reputation: 24448

You have 1 condition and 2 rules. Conditions only work for the first rewriterule following the last condition. You need another one with the way you are using them.

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]

Based on your comment.

If you want to consolidate you can do this.

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

Upvotes: 2

Related Questions