Forum Moderators: phranque
Im trying to consolidate all my urls for one site onto the one, main url. for example www.example.com is to be the main one with example.com, www.my-site.com, my-site.com, mysite.co.uk, my-site.co.uk all pointing to that main url
the reason for this is that Google is listing half of my site on one url and half on an other! no good!
i am trying to use these lines in my .htaccess but im getting 500 errors from the re-routed domains when i access them
if anyone can help with this it would be great, its hosted with fasthosts who suport i have exasted on this one
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?my-site\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?my-site\.co.uk [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.co.uk [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^my-site\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^mysite\.co.uk [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^my-site\.co.uk [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
thanks very much for any light you can throw my way on this one as my site's traffic is falling apart!
Regards,
Barry
[edited by: jdMorgan at 10:56 pm (utc) on Aug. 23, 2007]
[edit reason] Example.com [/edit]
For example, you may not be allowed to use the Options directive, depending on your host. If you are allowed to use it, it might be required or it might be unnecessary, again depending on your host.
You may not even be allowed to use mod_rewrite on some really-lousy hosts. The only way to determine these cases is to construct simple tests for each case. Be sure to completely flush your browser cache before testing any change to your code.
The only --and very minor-- problem I see is that you've got several instances of the incompletely-escaped pattern "...site\.co.uk", which should read "...site\.co\.uk". However, that won't cause a 500-Server Error.
Also, have you considered using just one rule to redirect all non-canonical domain requests?
# Externally redirect if NOT canonical domain
RewriteCond %{HTTP_HOST} [b]!^w[/b]ww\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
The (www\.)? in the first three rules means that they already work for both www and non-www URLs.
The fourth rule (correctly) only needs a rule for non-www requests.
You can use my(-)?site to make it match for both my-site and mysite.
You can also use \.co(m¦\.uk) to make it match for .com and .co.uk too.
.
... Or you could go with the !NOT one-liner that jd used.
everything now appears to be working well and im delighted :)
i removed the Options directive and went with the single rule as Jd proposed and hey presto!
so, for anyone else having a similar problem on Fasthosts Linux servers, here is the solution (thanks again gentlemen!)
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
[edited by: jdMorgan at 10:52 pm (utc) on Aug. 23, 2007]
[edit reason] Corrected formatting as noted below. [/edit]
i do have that space in my code, just not showing here so watch out for that anyone using that code!
one thing, after reading up all i can about this im hoping that this change will not only clean up the obvious problems that multiple urls in google present, but also shift all the pr from those other urls onto my main one. has this been your experience when doing this? how long does it take? and surely i wont end up with a pr8 site after my 2 pr4 urls have been combined will i? (he says in a childlike wonder sort of way!)
cheers lads
Barry