Forum Moderators: phranque
I'm looking for the most complete/simple way to send visitors who try to enter my site via .co.uk or .net etc. (anything that's not .com) to the .com version of the URL they're requesting?
Is there a simple and efficient way to do this with htaccess, I'm sure there is but I'm hopeless at this side of things.
Thank you!
Welcome to WebmasterWorld!
This question is essentially the same as the non-www to www domain redirects discussed in these threads [google.com]. The only difference is that you're basing the redirection on the tld being NOT(.com)
For more background information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim
I've spent a lot of time looking, usually I manage to find the answer (hence the first post and join dates being so far apart!), but I couldn't spot what I was after this time.
I've taken another look and still don't really get "it".
I'm sure there's a way to get (for example) http://www.example.co.uk/forum/forumdisplay.php?f=1
to redirect to http://www.example.com/forum/forumdisplay.php?f=1
I just cant seem to get my head around it. Previously I've given up and used php to do it, but I'm sure htaccess will prove more efficient (if I can fathom it!).
[edited by: jdMorgan at 7:36 pm (utc) on Oct. 14, 2005]
[edit reason] No URLs, please. See TOS. [/edit]
RewriteCond %{HTTP_HOST} !(www\.)example\.com
rewriterule (.*) http://www.example.com/$1 [R=301,L]
Works, as long as there's no path/file information passed, but if you add /forum it misses it.
[edited by: jdMorgan at 7:36 pm (utc) on Oct. 14, 2005]
[edit reason] No URLs, please. See TOS. [/edit]
RewriteEngine on
RewriteCond %{HTTP_HOST} !(www\.)?example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Jim