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]

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.