0

Given a username, I'd like to 'dynamically' create a sub domain.

I read the answers in

Create subdomains on the fly with .htaccess (PHP)

And though it's good, it's not working for me, (I think) because I have multiple domains on my server (I've asked my initial question here https://superuser.com/questions/720911/wildcard-subdomain-being-redirected-to-the-wrong-domain/720913?noredirect=1#comment923298_720913).

My set up is

  • Linode VPS
  • Apache
  • Ubuntu

I have multiple domains

  • abc.com
  • def.com

I want my dynamic sub domains on the second domain (e.g. x.def.com, y.def.com).

So I've created a wildcard DNS entry via my DNS manager.

But since "abc.com" is the first domain that's configured, it seems like it's doing "catch-all" for any subdomain in a form of "x.def.com".

Is it possible to still achieve the dynamic subdomain creation in my set up?

my virtual host set up is below

# in file /apache2/sites-available/abc.com 
<VirtualHost *:80>
  ServerName  www.abc.com

  DirectoryIndex index.php index.html
  DocumentRoot /home/website/public/abc.com/public/
</VirtualHost>

# in file /apache2/sites-available/def.com 
<VirtualHost *:80>
  ServerName  www.def.com
  ServerAlias *.def.com
  UseCanonicalName Off

  DirectoryIndex index.php index.html
  DocumentRoot /home/website/public/def.com/public/
</VirtualHost>
Community
  • 1
  • 1
ericbae
  • 9,604
  • 25
  • 75
  • 108
  • Can you post your current VirtualHost configuration? You'll need to have set your ServerAlias correctly for it to pick up wildcard sub domains. – arco444 Feb 26 '14 at 11:40

1 Answers1

0

That configuration looks OK to me. Make sure you have NameVirtualHost *:80 set in your main apache config file. If you're using Ubuntu this might be in ports.conf.

You can use apachectl -S to examine all the configured VirtualHosts. This should contain your wildcard alias if set up properly.

arco444
  • 22,002
  • 12
  • 63
  • 67