Charlie
Charlie

Reputation: 75

How to 301 redirect only one domain on server with multiple domains

I'm attempting to redirect a site of mine to another site, but there are other domains in the same folder.

How do I only redirect one specific domain to another domain? Would this work

RewriteRule http://oldomain.com/(.*)$ http://newdomain.com/ [L,R=301]

Upvotes: 0

Views: 761

Answers (1)

Croises
Croises

Reputation: 18671

No, you must use:

RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^ http://newdomain.com%{REQUEST_URI} [R=301,NE,L]

Or if you don't ask for the same file/directory in newdomain.com:

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

Upvotes: 1

Related Questions