Forum Moderators: phranque
RewriteCond %{HTTP_HOST} ^website\.com$ [NC]
RewriteRule ^(.*)$ http://www.website.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.website\.com
RewriteRule (.*) http://www.website.com/$1 [R=301,L] RewriteCond %{HTTP_HOST} !^www\.(.*)\.com
RewriteRule (.*)/(.*) http://www.$1.com/$2 [R=301,L]
Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ http://www.website.com/$1 [R=301,L]
!^www\. - does not begin www. ^([^.]+\.com)$ - captures domain name !^(www\.[^.]+\.com)$ - not "exactly" www.example.com ^(www\.[^.]+\.com) - captures domain name [edited by: g1smd at 8:33 pm (utc) on Aug 9, 2011]
RewriteCond looking at %{HTTP_HOST}, in order to do the right thing. RewriteRule RegEx pattern can match only the path part of the URL request, so use (.*) here to redirect all URLs. [R=301,L] flag. [edited by: g1smd at 9:57 pm (utc) on Aug 9, 2011]
RewriteRules will each have two preceding RewriteCond lines looking at %{HTTP_HOST}, using the four patterns discussed above.
RewriteRule !^(www\.[^.]+\.com)$/(*.) http://www.$1/$2 [R=301,L]