Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtualhost For Wildcard Subdomain and Static Subdomain

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.

like image 486
Dave Avatar asked Apr 16 '09 22:04

Dave


People also ask

Can you have a wildcard for a subdomain?

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.

What is 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.

How do I enable wildcard subdomains?

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.


1 Answers

<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.

like image 94
Tim Avatar answered Sep 17 '22 11:09

Tim