Forum Moderators: phranque
I am having some problems configuring my server to redirect subdomains correctly.
The following situation exists:
We are running a website that has regional website, we use the placename of the region as a subdomain for example and use one central site where visitors can select their region of choice, so our site has the following sites and subsites:
domainname.com (central site)
aalten.domainname.com (regional site)
gendringen.domainname.com (regional site)
breedenbroek.domainname.com (regional site)
admin.domainname.com (management panel)
Users also might enter www.aalten.domainname.com in their address bar, but i would like the user to be redirected to aalten.domainname.com this should happen for all regional domainnames and the admin site may be included in that.
In essence my wish is to always make Apache drop the www. portion used in the address bar and permanently redirect the user to the corresponding hostname without www.
Is this possible by one Directive which works for any subdomain?
With kind regards,
Erwin
# Externally redirect to canonical non-www hostnames
RewriteCond %{HTTP_HOST} ^www\.(([^.]+\.)*)example\.com
RewriteRule (.*) http://%1example.com/$1 [R=301,L]
Jim