I would like to redirect all subdomains and www to my main “non-www” domain.
So:
www.example.com AND sub.example.com AND www.sub.example.com
Should all become:
example.com
How could I do this using mod_rewrite
?
Thanks
I would like to redirect all subdomains and www to my main “non-www” domain.
So:
www.example.com AND sub.example.com AND www.sub.example.com
Should all become:
example.com
How could I do this using mod_rewrite
?
Thanks
This suggests the following redirects www.example.com
to example.com
:
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
As such, you could use the following to redirects anything that ends with .example.com
to example.com
:
RewriteCond %{HTTP_HOST} \.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
The following is a more generic solution (but it doesn't work for domains that are part of multi-level TLDs, such as www.theregister.co.uk
):
RewriteCond %{HTTP_HOST} \.([^.]+\.[^.]+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]