views:

1258

answers:

1

I have an odd situation where I want to have the urls app1.example.com, example.com and *.example.com all using a different virtual host. This is what I have (excluding example.com cause it just makes it messier)

ServerName app1.example.com ServerAlias app1.example.com

DocumentRoot = /var/www/app1 # Other configuration for this app here

ServerName wildcard.example.com ServerAlias *.example.com

DocumentRoot = /var/www/wildcard # other configuration for this app here

The problem is that they conflict. Whichever one is listed first wins out. How can I host both a wildcard virtualhost and a specific one?

Note: I'm not just changing DocumentRoot in the config, so using mod_rewrite to change the DocumentRoot variable does not fix it.

Thanks

+4  A: 
NameVirtualHost *:80

<VirtualHost *:80>
  DocumentRoot = /var/www/app1
  ServerName app1.example.com
<VirtualHost>

<VirtualHost *:80>
  DocumentRoot = /var/www/example
  ServerName example.com
<VirtualHost>

<VirtualHost *:80>
  DocumentRoot = /var/www/wildcard
  ServerName other.example.com
  ServerAlias *.example.com
<VirtualHost>

Should work. The first entry will become the default if you don't get an explicit match. So if you had app.otherexample.com point to it, it would be caught be app1.example.com. You need to turn on the name based virtual hosts with the first entry.

Tim