Forum Moderators: phranque
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Is there a way to write a condition that will do that rule unless the domain is already correct, i.e. www.example.com? Or is there a better way to go about this?
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
The provision for blank hostnames is needed to prevent an infinite loop on servers that can accept HTTP/1.0 requests, on the odd chance that you might get one (or a spoofed one).
Jim