I would like to set up my virtual hosts to do the following. For background, before I had access to virtual hosts, I did this on another server in .htaccess using entirely rewrite. As you can assume, this was extremely slow.
- Requests to example.com unchanged
- Requests to www.example.com permanantly redirected to example.com
- Requests to existing subdomain (a.example.com or b.example.com) unchanged, deliver their own content
- Requests to non-existing subdomain redirected to example.com
vhosts.conf
<VirtualHost *:80>
ServerName example.com
</VirtualHost>
<VirtualHost *:80>
ServerName a.example.com
</VirtualHost>
<VirtualHost *:80>
ServerName b.example.com
</VirtualHost>
<VirtualHost *:80>
ServerName www.example.com
Redirect permanent / http://example.com
</VirtualHost>
Issue 1
In this case, for some reason b.example.com
matches, but a.example.com
redirects
to example.com
. That seems odd.
Issue 2
rstlne.example.com
displays the contents of example.com, but address still shows rstlne.example.com
. That is expected, but I need to know how to redirect this case to example.com
. The only thing that comes to mind about redirecting non-existent domains would be to have the first (default) virtual host have the redirect, but in that case example.com
would match and be a redirect loop.