Forum Moderators: phranque
Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^[0-9]+(\.[0-9]+){3} [OR]
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://example.com/$1 [R=301,L]
Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^[0-9]+(\.[0-9]+){3} [OR]
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteEngine on
#
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
www.example.com./<anything-or-nothing> with trailing period on hostname, www.example.com:80/<anything-or-nothing> with port number on hostname, www.example.com and your code redirects only requests that do NOT begin with that. RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L] ( )? replaces the extra RewriteCond in your code. $ forces the redirect for any requested hostname that is not "exactly" www.example.com