Click to See Complete Forum and Search --> : Mod_Rewrite: Redirect Domain
Hi,
How would I go about redirecting all visitors to www.domain.co.uk to www.domain.com using mod_redirect?
I do know how to do this via a PHP location header but I understand that doing it via htaccess is better (plus I need ALL sub-URLs to go to the same place under the .com
Thank you for taking the time to look at this and (hopefully) helping me :o)
Many thanks,
atw
This should work in an .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
desuma09
10-06-2008, 10:22 AM
how can i make it so it doesnt add the www. to my domain wen I go on labs.mydomain.com.
Thanks
Just place this in your .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.yourSite.com$
RewriteRule ^(.*)$ http://yourSite.com/$1 [R=301,L]
And then you can check here (http://www.seoconsultants.com/tools/headers.asp) to make sure you're getting a true 301 re-direct. Check it with the "www." added to the beginning.
desuma09
10-06-2008, 11:20 AM
I already have the following line to insert www to all pages
RewriteCond %{HTTP_HOST} !^www\..* [NC]
RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R=301]
however the only time i dont want it to add it is when I go to labs.mydomain.com..
I inserted your code like this... but im getting a bad loop effect..
RewriteCond %{HTTP_HOST} ^www.labs.mydomain.com$
RewriteRule ^(.*)$ http://labs.mydomain.com/$1 [R=301,L]
Sorry if im being confusing...
thanks
You can't use both codes. I'll have to look later for what you want with just the one.
desuma09
10-07-2008, 04:10 AM
thanks, would appreciate that!!