Take the 2-minute tour ×

Does anyone know how can I do a 301 redirect traffic from one domain to the other - including all the same url elements after domain name - and apply the same rule to all possible links without writing it for each url separately - example would be something like this:


to redirect to:


At the moment I have something like this:

RewriteRule ^/?$ "http\:\/\/www\.newdomain\.com" [R=301,L]

but this won't work for the following situation for instance:


it simply won't redirect to the new domain and keep the /login.html after.

Any clues?

share|improve this question
add comment

3 Answers

Ok - after a lot of googling I've found the solution - which comes to a simple two lines:

RewriteCond %{HTTP_HOST} !^www\.newdomain\.com$ [NC]

Thanks everyone for participating.

share|improve this answer
add comment

Youre RewriteRule is incorrect. You're only redirecting http://www.olddomain.com/ but not /login.html

Try modifying the rewrite rule to include all paths on the old domain:

RewriteRule ^(.*)$ http://www.newdomain.com$1 [R=301,L]
share|improve this answer
yes - but this one is not going to redirect me to 'newdomain.com/login.html'; - it will redirect me directly to 'newdomain.com'; if I type 'olddomain.com/login.html'; - so not really what I'm looking for –  user398341 Jul 9 '11 at 18:29
@user398341 You missed the $1 at the end. (.*) captures the path at the old domain and I refer to that using $1 in the redirect. So it should redirect olddomain.com/login.html to newdomain.com/login.html –  nxt Jul 9 '11 at 19:27
Doesn't seem to make any difference I'm afraid. –  user398341 Jul 10 '11 at 8:42
It appears we were missing forward slash after '.com' –  user398341 Jul 10 '11 at 9:39
add comment

Have you tried simply:

Redirect 301 / http://newdomain.com/

In the root folder of olddomain.com

share|improve this answer
add comment

Your Answer


