Wildcard subdomains, block all other
I'm having a few issues with my new VPS just bought. I'm trying to configure Apache to accept wildcare subdomains on my main website, but allowing this also means that I can't block all others except the one created.
To be more explicit, I'm having this:
subdomain1.domain.com
-> redirects correctly (CNAME added, folder ok, everything ok)
subdomain2.domain.com
-> same as subdomain1
subdomainN.domain.com
-> the subdomainN doesn't exist. Thus, if I write "stackoverflowreallyrocks.domain.com" I'm being redirect to my stackoverflowreallyrocks.domain.com, with the content of domain.com - which isn't good.
Is there a way to redirect all subdomains that doesn't exists to domain.com?
The httpd.开发者_StackOverflow社区conf
for the main domain is:
<VirtualHost *:80>
DocumentRoot "/home/domain"
ServerName www.domain.com
ServerAlias domain.com
</Virtualhost>
<VirtualHost *:80>
ServerName subdomain1.domain.com
DocumentRoot "/home/domain/_subdomain1"
</VirtualHost>
<VirtualHost *:80>
ServerName subdomain2.domain.com
DocumentRoot "/home/domain/_domain2"
</VirtualHost>
Try adding another VirtualHost
to the bottom of the config:
<VirtualHost *:80>
ServerName *
ServerAlias *
</Virtualhost>
The other VirtualHost
entries should still match as they are better matches, and are prior to the wildcard host, allowing non-matching requests to fall into this last VirtualHost
精彩评论