Htaccess rule for redirecting .co.uk to .com

Hi,

How can I redirect https://www.mydoman.co.uk/slug1/slug2 to https://www.mydoman.**com**/slug1/slug2 ?

Thanks

What have you tried so far?

Hi @rpkamp

Ive tried:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]

Which I got from this https://stackoverflow.com/questions/8763891/htaccess-redirect-co-uk-to-com-for-all-pages/8763931

But that has no effect. I thought it may be because it was conflicting with something else in my htaccess file, so I removed everything else in my htaccess file, but it still didnt do anything. Very odd.

I don’t know if this is any help:

https://perishablepress.com/stupid-htaccess-tricks/#red3

I haven’t tried that particular scenario, but I’ve found that article helpful in the past.

Hmmm, none of those examples will work. I tried the specific one you linked to, but it just results in an infinite loop.

However, I did try a variation

RedirectRule 301 https://www.domain.co.uk/(.*) https://www.domain.com/$1

But that didnt work either. :unamused:

1 Like

OK, Ive got it working!

Ive used

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

No idea why that works and the others didnt. I will investigate further.

Thanks all for your help.

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.