I have a variety of sites that are subdomain specific sites. http://sub.domain.com http://apple.domain.com etc.
users occasionally complain that the site is not working and then i find out they went to http://www.sub.domain.com or http://www.apple.domain.com and are met with a server error page of sorts
what kind of htaccess magic do i need to turn http://www.sub.domain.com -> http://sub.domain.com
thanks
*fwiw i did search through previous questions before asking and did not find my answer
If the VHost is really pointing to the same docroot for www.sub.domain.com and sub.domain.com, you can place a .htaccess-file with following content in the doc-root:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^sub\.domain\.com$ [NC]
RewriteRule (.*) http://sub.domain.com$1 [R=301,L]
That will redirect all domains which are pointing to this docroot to sub.domain.com
EDIT:
For multiple Subdomains in one single .htaccess-file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.([^\.]*)\.domain\.com$ [NC]
RewriteRule (.*) http://%1.domain.com$1 [R=301,L]
This is untested from top of the head.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With