martinjbaker
martinjbaker

Reputation: 1484

htaccess rewrite rule to redirect specific page on specific domain to another url

I'm hosting 2 sites on the same server with different domains. I'd like to set up a redirect for a specific page on domain 1 and have it go to another external url. Have searched and searched and experimented but can't get it work.

The nearest I've got is

RewriteRule ^oldpagename$ http://externalsite/page [R=301,L]

but the problem with this is that it catches that url on the other domain as well. How can I restrict it to a specific domain?

thanks

Upvotes: 1

Views: 4550

Answers (1)

Jon Lin
Jon Lin

Reputation: 143966

You need to add a condition to match against the variable `%{HTTP_HOST}:

RewriteCond %{HTTP_HOST} ^(www\.)?domain1.com$ [NC]
RewriteRule ^oldpagename$ http://externalsite/page [R=301,L]

Upvotes: 4

Related Questions