bird

msg:3146439 | 9:27 am on Nov 5, 2006 (gmt 0) |
RewriteCond %{HTTP_HOST} !^$ RewriteCond %{HTTP_HOST} !^www\.example\.com RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
The first line is needed for very old browsers (or robots) who don't support virtual hosting, so they won't cause infinite redirects.
|
stever

msg:3146443 | 9:30 am on Nov 5, 2006 (gmt 0) |
I had this on a domain a while back and added the following to the .htaccess file: Deny from baddomain.info I'll leave it to the mod-rewrite experts to say if that is kosher, but it seemed to work for me.
|
jtara

msg:3146796 | 9:21 pm on Nov 5, 2006 (gmt 0) |
All that is going to to is deny any requests made FROM the baddomain.info server. But they don't have one, so this does nothing in this case. bird's solution is the correct one. It will rewrite to your domain and avoid a duplicate-content penalty. Not only that, but you pull one over on the bad guy - YOU get the credit for his traffic.
|
cassandra

msg:3146871 | 12:21 am on Nov 6, 2006 (gmt 0) |
Hi bird, Thanks for the rewrite code I am also using sub domains, would this code effect subdomains. Could you please explain what does the second line do? Thanks.
|
jdMorgan

msg:3146879 | 12:30 am on Nov 6, 2006 (gmt 0) |
Line by line:
# If requested hostname is NOT blank RewriteCond %{HTTP_HOST} !^$ # AND requested hostname is NOT my canonical domain name RewriteCond %{HTTP_HOST} !^www\.example\.com # THEN redirect to requested page using canonical domain RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Jim [edit] Formatting [/edit] [edited by: jdMorgan at 12:46 am (utc) on Nov. 6, 2006]
|
stever

msg:3146883 | 12:36 am on Nov 6, 2006 (gmt 0) |
Thanks for that explanation.
|
|