jasonc Posted June 5, 2011 Share Posted June 5, 2011 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] Quote Link to comment https://forums.phpfreaks.com/topic/238470-how-to-rewriterule-for-either-couk-or-com-to-rewrite-to-wwwsitecom/ Share on other sites More sharing options...
requinix Posted June 5, 2011 Share Posted June 5, 2011 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] Quote Link to comment https://forums.phpfreaks.com/topic/238470-how-to-rewriterule-for-either-couk-or-com-to-rewrite-to-wwwsitecom/#findComment-1225416 Share on other sites More sharing options...
jasonc Posted June 5, 2011 Author Share Posted June 5, 2011 i tried that code but when i checked it using site.com and site.co.uk i am not taken to the www.site.com, i wish to have the www.site.com as my main site. Quote Link to comment https://forums.phpfreaks.com/topic/238470-how-to-rewriterule-for-either-couk-or-com-to-rewrite-to-wwwsitecom/#findComment-1225421 Share on other sites More sharing options...
requinix Posted June 6, 2011 Share Posted June 6, 2011 Did you keep the RewriteEngine On you had before? What's your .htaccess now? Quote Link to comment https://forums.phpfreaks.com/topic/238470-how-to-rewriterule-for-either-couk-or-com-to-rewrite-to-wwwsitecom/#findComment-1225776 Share on other sites More sharing options...
jasonc Posted June 6, 2011 Author Share Posted June 6, 2011 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] Quote Link to comment https://forums.phpfreaks.com/topic/238470-how-to-rewriterule-for-either-couk-or-com-to-rewrite-to-wwwsitecom/#findComment-1225778 Share on other sites More sharing options...
HDFilmMaker2112 Posted June 6, 2011 Share Posted June 6, 2011 Do you have cpanel? Why not just put the domains you want forwarded in as add-on domains and set-up a redirect under CPanel. Quote Link to comment https://forums.phpfreaks.com/topic/238470-how-to-rewriterule-for-either-couk-or-com-to-rewrite-to-wwwsitecom/#findComment-1225782 Share on other sites More sharing options...
jasonc Posted June 6, 2011 Author Share Posted June 6, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/238470-how-to-rewriterule-for-either-couk-or-com-to-rewrite-to-wwwsitecom/#findComment-1225784 Share on other sites More sharing options...
requinix Posted June 6, 2011 Share Posted June 6, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238470-how-to-rewriterule-for-either-couk-or-com-to-rewrite-to-wwwsitecom/#findComment-1226042 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.