Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I want to redirect a .co.uk to .com:

  • example.co.uk/any-file-or-folder and
  • example.com/any-file-or-folder to
  • www.example.com/any-file-or-folder.

I've refered to this question/answer: htaccess and 301 redirects - multiple domains.

Which lead me to write:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

Which redirects example.co.uk and example.com to www.example.com just fine but example.co.uk/test/ does not go to www.example.com/test/.

Any pointers on where I am going wrong?

share|improve this question
    
What you have looks as it if it should work? Do you have any other directives in your .htaccess file? –  w3d May 15 at 19:42
    
Its a wordpress site, so the usual wordpress stuff, nothing extra. –  MrG May 16 at 12:34
    
And your new redirects are at the top of the file, above the WordPress "stuff"? –  w3d May 16 at 13:03
    
Yup, the code above is the first thing in the htaccess file. –  MrG May 16 at 13:16
    
Hhmm, well that's certainly a puzzle! The code above, by itself, should work. Is this .htaccess file in the root of your site? Do you have any other domains hosted on this account? (If not, your code could be simplified a tad.) The RewriteBase line is also superfluous here. What actually happens when you navigate to example.co.uk/test/ or example.com/test/? –  w3d May 16 at 13:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.