Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess redirect .co.uk to .com for all pages

Im migrating my website from the .co.uk to the .com but need to setup a 301 redirect so all of the individual pages will still be routed properly.

ie i want http://www.mydomain.co.uk/shopping/product1 to go to http://www.mydomain.com/shopping/product1

I have done this before but for the life of me cannot remember how.

many thanks

paul

like image 449
user1135090 Avatar asked Jan 06 '12 20:01

user1135090


People also ask

How do I redirect a whole domain?

To 301 Redirect an Entire Domain:Replace http://www.new-domain.com/ with the URL that you would like your site to redirect to. Be sure to add a blank line at the end of your . htaccess document.


1 Answers

RewriteEngine On
RewriteBase /

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

This redirects both the www and non-www for mydomain.co.uk to www.mydomain.com.

like image 120
Jason McCreary Avatar answered Sep 27 '22 22:09

Jason McCreary