Jump to content

How to RewriteRule for either .co.uk or .com to rewrite to www.site.com


jasonc

Recommended Posts

I wish to have the website use the www.site.com address as a rule.

 

So if they use site.com site.co.uk www.site.co.uk they get taken to www.site.com

 

How do I have the following code work for either domain name be it the .co.uk or the .com address

 

RewriteEngine on
RewriteCond %{HTTP_HOST} ^site.co.uk
RewriteRule ^(.*)$ http://www.site.co.uk/$1 [R=301,L]
#ewriteCond %{HTTP_HOST} ^site.co.uk$ [OR]
#ewriteCond %{HTTP_HOST} ^www.site.co.uk.com$
#RewriteRule ^.?$ "http\:\/\/site\.com\/$1" [R=301,L]

#RewriteEngine on
#RewriteCond %{HTTP_HOST} ="site.co.uk"
#RewriteRule (.*) http:/www.site.co.uk/$1 [R=301,L]

Your title suggests you want everything to redirect to .com but your post suggests otherwise.

 

Try one rule to catch the non-www domain names and one rule to catch all the other incorrect names.

RewriteCond %{HTTP_HOST} !^www.site.(com|co.uk)$
RewriteCond %{HTTP_HOST} (^|.)site.(com|co.uk)$
RewriteRule ^ http://www.site.%3%{REQUEST_URI} [L]

RewriteCond %{HTTP_HOST} !^www.site.(com|co.uk)$
RewriteRule ^ http://www.site.com%{REQUEST_URI} [L]

my .htaccess  file

RewriteCond %{HTTP_HOST} !^www.site.(com|co.uk)$
RewriteCond %{HTTP_HOST} (^|.)site.(com|co.uk)$
RewriteRule ^ http://www.site.%3%{REQUEST_URI} [L]

RewriteCond %{HTTP_HOST} !^www.site.(com|co.uk)$
RewriteRule ^ http://www.site.com%{REQUEST_URI} [L]

what i am after is if a visitor vists

site.co.uk

site.com

they get taken to

www.site.com

 

also if they visit say

www.site.co.uk/mypage.php

site.co.uk.myotherpage.php

site.com/somethingelse.php

 

they get taken to that page but under the .com url instead.

www.site.com/ThePageTheyWanted.php

Okay, so your thread title was the more accurate description...

RewriteCond %{HTTP_HOST} !^www.site.com$
RewriteRule ^ http://www.site.com%{REQUEST_URI} [L]

Keep the RewriteEngine you had before. Still need that.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.