jazzdrive3
jazzdrive3

Reputation: 335

Using .htaccess to redirect from one folder to another, if domain matches

I need to rewrite all URLs from one folder to another folder, but only if they are doing a request from a certain domain.

So:

www.example.com/blog/path/to/article

needs to go to:

www.example.com/new-blog/path/to/article

But it needs to be conditional to example.com, because if the request comes through for, say:

www.otherdomain.com/blog/path/to/article

it does not need to redirect to the new folder.

Both the folders "blog" and "new-blog" contain two separate Wordpress installs. This is the code I currently have in the root public folder, and what does not work:

RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^blog(.*) /new-blog$1 [L,R]

Any help is appreciated. Thanks.

Upvotes: 0

Views: 586

Answers (1)

jazzdrive3
jazzdrive3

Reputation: 335

I was able to get it working with this directive, and actually placed inside the /blog folder:

RewriteCond %{HTTP_HOST} ^new\.example\.com$ [NC]
RewriteRule (.*) http://new.example.com/our-happy-place/$1 [L,R]

Upvotes: 1

Related Questions