Forum Moderators: phranque
I want that my main domain is browsed with www i.e.
www.example.com
I have already made entry for this
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [R=301,L]
and all my sub-domains are browsed without www i.e.
[abc.example.com...]
[bcd.example.com...]
.......
[xyz.example.com...]
Can anyone help.
# Redirect to canonicalize example.com, www.<subdomain>.example.com, <subdomain>.example.com.,
# <subdomain>.example.com:80, and <subdomain>.example.com.:80, etc.
RewriteCond www.%{HTTP_HOST} ^(www)\.example\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.([a-z0-9\-]+)\.example\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^([a-z0-9\-])\.example\.com(\.¦\.?:[0-9]+)$ [NC]
RewriteRule ^(.*)$ http://%1.example.com/$1 [R=301,L]
As written, this code is for use in the top-level .htaccess file or within a <Directory> container in a server config file such as httpd.conf. If this code is to be used in a server config file outside of any <Directory> container, then change the RewriteRule pattern to "^/(.*)$" -- i.e. add the leading slash before the parentheses.
Jim
Jim