【问题标题】:ServerAlias Name [closed]ServerAlias 名称 [关闭]
【发布时间】:2011-07-09 17:31:35
【问题描述】:

我想在 httpd.conf 的服务器别名中添加一个异常,例如 not xx.com。

谢谢 让

【问题讨论】:

标签: .htaccess mod-rewrite


【解决方案1】:

据我所知,ServerAlias 一次只匹配一个域。添加异常的唯一方法是不使用该域的 ServerAlias。

如果你不想让VirtualHost匹配xx.com,那么不要把ServerAlias xx.com放在VirtualHost中,你应该没问题吧?

我猜这不是你的问题,因为这很明显,所以让我猜猜你可能会问的其他问题:

如果您正在寻求一种方法来执行匹配多个域的通配符 ServerAlias,您可能应该使用 mod_rewrite 而不是依赖 Apache 的 VirtualHost 有限解析。它非常强大且基于正则表达式,可以处理各种通配符和模式。

另一方面,如果您想为 xx.com 上的特定 URL 添加异常并将该 URL 指向不同的 VirtualHost,也可以使用 mod_rewrite 完成。

简而言之,看看 mod_rewrite,看看它是否能帮助你做你需要做的事情。

我还想到,您可能会混淆第一个 VirtualHost 的行为。第一个 VirtualHost 始终是默认值。如果没有其他 VirtualHost 匹配,则第一个将始终用于 Apache 接收的任何域。从默认 VirtualHost 中“排除”域的唯一方法是添加自己的特定 VirtualHost 来捕获它。无论如何,mod_rewrite 很可能也会成为你的朋友。

编辑:这是我的 VirtualHost 配置中的一个 sn-p,也许这会帮助你理解我告诉你要做什么:

<VirtualHost *:80>

    # This is the default VirtualHost, because it is listed first.
    # All domain names that are not recognized elsewhere go here
    # automatically. All this VirtualHost does is to display a simple
    # HTML page informing users that no site exists at that address.

    # ServerName/Alias doesn't matter, because it's not a real vhost
    ServerName default-vhost.mysite.net
    DocumentRoot /var/www/nosite

    # In case someone goes to http://unknownsite.com/something/else.html
    # make sure they get the "no site" message, so redirect all URLs.
    RewriteEngine On
    RewriteRule ^/(..*) /index.html [NS]
</VirtualHost>

<VirtualHost *:80>
    # This is my real website. Because it is listed second, it will ONLY
    # be accessible from hostnames listed as ServerName or ServerAlias

    ServerName mysite.net
    DocumentRoot /var/www/mysite
</VirtualHost>

【讨论】:

  • 长话短说,网络主机存在 .htaccess 问题,否则这是我最好的选择,现在我需要排除
  • 那么让我看看我是否理解。您有一个具有ServerAlias x.com 的 VirtualHost,但是当您访问 x2.com 时,您会得到 x.com VirtualHost?
  • 我有 ServerAlias x !x2 那就是当它是 !x2 时我不想要任何重定向
  • @Jean 这没有任何意义。请提出一个真实世界的例子,正如现在反复要求的那样。
  • ServerAlias 无法做到这一点。删除!x2。它行不通。要排除 x2,您需要做的是添加另一个 VirtualHost,并使其具有SeverName x2。然后所有对 x2 的 VirtualHost 请求都会去那里。这是从默认 VirtualHost 中排除它的唯一方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-20
  • 2021-08-23
  • 2019-12-18
  • 1970-01-01
  • 2019-07-28
相关资源
最近更新 更多