The settings
I have the following .htaccess rule
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^de\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
This works great to redirect any subdomain that is not valid (www
or de
) to the www
subdomain.
I have seen solution, but they only depend on single domain sites.
I have multiple domains:
http://www.example.com
http://www.example.net
http://de.example.com
which all serve their own brand of site.
Now I have the .htaccess rule that is mentioned above and it works beautifully if someone types in http://example.com
it redirects to http://www.example.com
.
The problem
If someone types in http://test.example.com
, it redirects to http://www.test.example.com
and if someone types in http://test.example.net
, it redirects to http://www.test.example.net
.
The question
How can I make it so that it redirects http://test.example.com
to http://www.example.com
? And http://test.example.net
to http://www.example.net
.
I need an domain insensitve solution because more domains will be added in the future.