0

I have a question about vhost_alias

I got it working, it does the following job:

vhost.subdomain.domain.com -> sends to /var/www/vhost

using virtualdocumentroot and %1

But I don't like that I can access the same content also like this

vhost.vhost.subdomain.domain.com

since I have ServerAlias to *.subdomain.domain.com

How can I force that only vhost.subdomain.domain.com works?

The aim is to have many vhosts like this, for exmaple vhost1, vhost2, etc.

Thanks, David

user2042985
  • 95
  • 1
  • 1
  • 9
  • Do not set a wildcard alias if you don't want that behaviour. – Tolsto Jan 11 '14 at 21:45
  • OK, but what should I put in ServerAlias? Thanks – user2042985 Jan 11 '14 at 22:21
  • You don't have to specify a ServerAlias if you do not need one. That is the case if you want your server to be only reachable under vhost.subdomain.domain.com – Tolsto Jan 11 '14 at 22:22
  • I have both ServerName and ServerAlias set, ServerName is default.subdomain.domain.com and ServerAlias is *.subdomain.domain.com because I need this vhost to accept vhost1.subdomain.domain.com, vhost2.subdomain.domain.com, etc. Can I do that better way? Thanks – user2042985 Jan 11 '14 at 22:27
  • Okay, I see your problem now. I would suggest to configure your DNS server in a way that it will not redirect *.vhostX.subdomain.domain.com to your server but only *.subdomain.domain.com – Tolsto Jan 11 '14 at 22:29
  • I'm interested in solution at "Apache level" but thank you very much for your time. – user2042985 Jan 11 '14 at 22:31
  • Well, you could then try to set another vhost with ServerAlias *.*.subdomain.domain.com. It should catch the second level subdomains. However, the vhost order in your config is important then. – Tolsto Jan 11 '14 at 22:47

1 Answers1

0

One solution you could try is to add a fixed subdomain in your ServerAlias, before your actual dynamic subdomain:

Example:

ServerAlias www.*.subdomain.domain.com

This will ensure that

vhost.vhost.subdomain.domain.com

does not redirect, however, you will be forced to always add www. before your name.

Go0se
  • 98
  • 1
  • 8