.htaccess redirect .co.uk to .com

Soldato
Joined
18 Oct 2003
Posts
19,415
Location
Midlands
Hello chaps,

I'm struggling with this at the moment. I can redirect .co.uk to .com, not a problem. The issue I have is example.co.uk/something/ remains on the .co.uk.

I want to redirect all .co.uk/ requests to the same page but replacing the .co.uk with .com.

So if you tried to access www.example.co.uk/waffles/ your URL would be rewritten to www.example.com/waffles/

Any help is much appreciated.

Or, if anyone has any ideas about a better way to set up 2 sites .co.uk and .com pointing to the same content I am all ears.
 
Last edited:
Code:
# This allows you to redirect your entire website to any other domain
Redirect 301 / http://example.com/

Does that work?

Maybe directing the .co.uk domain to point to the .com domain via cpanel?

Would try it out for you but not at home PC right now!
 
But the same redirect will be served for the .com because both domains are pointing at the same files. That creates an infinite 301 loop and Google won't like that.
 
Ok, well I've decided not to try and rewrite the URL but actually 301 the entire .co.uk domain to the .com using DNS, which is probably the right way to do it. I'd still be interested to hear what other people think is the right setup.
 
So if you tried to access www.example.co.uk/waffles/ your URL would be rewritten to www.example.com/waffles/

Hmmm, thats in the realms of web spoofing/phishing. A lot of browsers are combating that sort of activity and flagging it as "suspicious".

The better idea would be set up a separate virtual folder for the .co.uk and then redirect to the .com which would have its own web space. Or use a 404 error page that contains some code to send the user to the same .com location.
 
the redirect I used when i last moved my site was(in .htaccess):

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.urlhere.co.uk/$1 [R=301,L]

I tried going to the old domain with a path and it took me to the path on the new domain. Hope it helps or is what you are after.
 
Last edited:
The better idea would be set up a separate virtual folder for the .co.uk and then redirect to the .com which would have its own web space. Or use a 404 error page that contains some code to send the user to the same .com location.

I tried going to the old domain with a path and it took me to the path on the new domain. Hope it helps or is what you are after.

I have thought about doing this too. I think I will try this route if the proper DNS redirects don't work. Just set up the .co.uk as its own site in IIS and then it can have its own htaccess rules to permanently redirect all traffic to the .com. Hopefully as Mtx says, it should redirect appropriately with paths too. Thanks guys.
 
Back
Top Bottom