Forum Moderators: phranque
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} "dts agent" [NC]
RewriteRule .* - [F] RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_USER_AGENT} "dts agent" [NC]
RewriteRule .* - [F] [edited by: jdMorgan at 12:18 am (utc) on Apr 19, 2010]
[edit reason] example.com [/edit]
RewriteCond %{HTTP_USER_AGENT} "dts agent" [NC]
RewriteCond %{HTTP_USER_AGENT} ="dts agent" [NC] RewriteCond %{HTTP_USER_AGENT} ^dts\ agent$ [NC]
RewriteCond %{HTTP_USER_AGENT} dts\ agent [NC]
Consider also a request for the valid but non-canonical hostname www.example.com.:80
Your code will not redirect that request, because it only looks for "example.com" variants.
So, you might consider using something like this, if you don't require any other subdomains in addition to "www":
[code]
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]