title: Creating Wildcard Sub Domain Using Apache VirtualHost
body: <p>I want to have this situation :</p>
  
  <ol>
  <li><p>if user request using this URL : <code>example.com</code> or <code>www.example.com</code>,
  user will see <code>index.php</code> in this directory <code>/home/admin1/public_html/</code></p></li>
  <li><p>but when user request using other sub domain (wildcard) for example : <code>freediscount.example.com</code>, user will see <code>index.php</code> in this path : <code>/home/admin1/public_html/userweb/freediscount.example.com</code></p></li>
  </ol>
  
  <p>technical support on my hosting suggest me to use this method : <a href="http://www.wiredstudios.com/php-programming/setting-up-wildcard-dns-for-subdomains-on-cpanel.html" rel="nofollow noreferrer">http://www.wiredstudios.com/php-programming/setting-up-wildcard-dns-for-subdomains-on-cpanel.html</a></p>
  
  <p>based on that tutorial, the PHP has a new job... to redirect on specific folder when user request with sub domain. I don't like this method. for me, it would be better if Apache can handle this.</p>
  
  <p>nearly close to what I need is this method : <a href="https://stackoverflow.com/questions/758351/virtualhost-for-wildcard-subdomain-and-static-subdomain">Virtualhost For Wildcard Subdomain and Static Subdomain</a></p>
  
  <p>but, I have a problem with <code>VirtualHost</code> setting, how to create <code>VirtualHost</code> correctly for that situation?</p>
  
  <p>here's what I've done but didn't work :</p>
  
  <pre><code>## I think this one is for www or without www, automatically generated with WHM
  &lt;VirtualHost xx.xx.xx.xx:80&gt; 
  ServerName example.com
  ServerAlias www.example.com
  DocumentRoot /home/admin1/public_html
  &lt;/VirtualHost&gt;
  
  ## Here's what I'm trying to add
  &lt;VirtualHost xx.xx.xx.xx:80&gt;
      ServerName example.com
      DocumentRoot /home/admin1/public_html/userweb/*
  &lt;/VirtualHost&gt;
  </code></pre>