I'm trying to meet a customer requirement to allow subdomains in the URL but also rewrite example.com to www.example.com.
The following works, but it doesn't rewrite "example.com" to "www.example.com". I'm not sure how to handle that.
- Code: Select all
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^localhost [NC]
RewriteCond %{HTTP_HOST} !^127\.0\.0\.1 [NC]
RewriteCond %{HTTP_HOST} !^server_hostname.example.com [NC]
RewriteCond %{HTTP_HOST} !^server_hostname [NC]
RewriteCond %{HTTP_HOST} ^(www)?([a-z0-9-]).example.com [NC]
RewriteRule ^/(.*) %2.example.com/$1 [L,R=301]