通配符子域,阻止所有其他
我刚购买的新 VPS 遇到了一些问题。我正在尝试将 Apache 配置为接受我的主网站上的 wildcare 子域,但允许这一点也意味着我无法阻止除创建的子域之外的所有其他子域。
更明确地说,我有这个:
subdomain1.domain.com
->正确重定向(CNAME 添加,文件夹正常,一切正常) subdomain2.domain.com
->与 subdomain1 相同
subdomainN.domain.com
->子域N不存在。因此,如果我写“stackoverflowreallyrocks.domain.com”,我将被重定向到我的 stackoverflowreallyrocks.domain.com,其中包含 domain.com 的内容 - 这不好。
有没有办法将所有不存在的子域重定向到domain.com?
主域的 httpd.conf
是:
<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>
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.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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将另一个
VirtualHost
添加到配置底部:其他
VirtualHost
条目仍应匹配,因为它们匹配得更好,并且位于通配符主机之前,允许不匹配请求落入最后一个VirtualHost
Try adding another
VirtualHost
to the bottom of the config: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 lastVirtualHost