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
because it just makes it messier).
<VirtualHost *> ServerName app1.example.com ServerAlias app1.example.com DocumentRoot = /var/www/app1 # Other configuration for this app here </VirtualHost> <VirtualHost *> ServerName wildcard.example.com ServerAlias *.example.com DocumentRoot = /var/www/wildcard # other configuration for this app here </VirtualHost>
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.
A wildcard subdomain is particularly useful if you desire subdomains to display whatever you set as the document root (a designated folder that stores web pages.) Typically, most wildcards are set to the site's homepage out of preference. This should be specified when creating the wildcard subdomain.
Wildcard subdomain allows you to point all non-existing subdomains to a specific folder in your account. It means that if you enter different subdomains (which are not created in your cPanel) in your browser, they all will show the same content that you uploaded to the folder set for the wildcard subdomain.
In other words, with a wildcard subdomain, it will not matter whether someone accesses your site through ww.yourdomain.com or wwwwww.yourdomain.com, they will still be taken to your home page. To enable the wildcard subdomain, go to your Site Tools > Domain > Subdomains.
<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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With