Redirected domain still displays "old" URL

I have three domains redirecting to a fourth. The .htaccess code for each is:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^olddomain\\.co\\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\\.olddomain\\.co\\.uk$
RewriteRule ^/?$ "http\\:\\/\\/www\\.newdomain\\.co\\.uk" [R=301,L]

This works fine for two domains, which have never been used for a site, but there’s a problem with the third. Until recently, there was a site there, although for the last few months it just consisted of a single page. (www.) redirects correctly to [noparse][/noparse], but old links which went to, while they show the new site, still display the old URL in the address bar.

What have I missed?


I believe that you’ve insisted that index.html NOT be in the {REQUEST_URI} variable.


RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\\.)?.olddomain\\.co\\.uk [NC]
RewriteRule .? [R=301,L]

The changes I made to your code (and the reasons) were:

  1. It’s easy to combine the RewriteCond regex to account for the www’d and non-www’d domains.
  2. The {HTTP_HOST} variable is case sensitive while the domains are not - the No Case flag resolves this problem.
  3. Your code insisted on NOTHING in the {REQUEST_URI} (except the / for ancient servers - pretty safe to ignore the leading /'s these days). I used .? to yield a TRUE value for every request (to
  4. PLEASE, don’t use \'s to escape characters in a redirection! While they won’t yield an error, they’re superfluous and make the code look ridiculous.



Thanks, DK - that’s great.

I actually set up the redirects through cpanel, so that’s the code it generated. I’ll know better for next time. :slight_smile:

Edit: Sorry, should have tried that before replying. It’s actually made the problem worse. Now all three domains display the wrong URL. :frowning:

It may be just a stray period.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?.olddomain\.co\.uk [NC]
RewriteRule .? [R=301,L]

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.co\.uk [NC]
RewriteRule .? [R=301,L]

And so it proved, because that works perfectly, thank you. :slight_smile: