apache - 通配符子域和静态子域的虚拟主机

标签 apache subdomain virtualhost wildcard-subdomain

我有一个奇怪的情况,我想要 URL app1.example.comexample.com*.example.com 全部使用不同的虚拟主机。这就是我所拥有的(不包括 example.com 因为它只会让事情变得更困惑)。

<VirtualHost *>
  ServerName app1.example.com
  ServerAlias app1.example.com

  DocumentRoot = /var/www/app1
  # Other configuration for this app here

</VirtualHost>

<VirtualHost *>
  ServerName wildcard.example.com
  ServerAlias *.example.com

  DocumentRoot = /var/www/wildcard
  # other configuration for this app here

</VirtualHost>

问题是它们之间存在冲突。最先列出的一方获胜。如何同时托管通配符虚拟主机和特定虚拟主机?

注意:我不只是更改配置中的 DocumentRoot,因此使用 mod_rewrite 更改 DocumentRoot 变量并不能解决问题。

最佳答案

<VirtualHost *:80>
  DocumentRoot /var/www/app1
  ServerName app1.example.com
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot /var/www/example
  ServerName example.com
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot /var/www/wildcard
  ServerName other.example.com
  ServerAlias *.example.com
</VirtualHost>

应该可以。如果您没有获得显式匹配,第一个条目将成为默认条目。因此,如果您让 app.otherexample.com 指向它,它将被捕获为 app1.example.com。

关于apache - 通配符子域和静态子域的虚拟主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/758351/

相关文章:

php - laravel redirect::back() 重定向到 favicon

php - 将每个人从东部标准时间上午 8 点到午夜的网站访问权限更改为从午夜到上午 8 点只有我的 IP

apache - 在单个子域上使用 SSL 的 Phpmyadmin

apache - 使用具有自定义主机名的 VirtualHost 时调试 400 (apache)

apache将单个子域映射到文件夹

android - 如何使用 Android SDK 模拟器查看本地托管的项目?

apache - 如何重置 httpd.conf 文件

windows - apache on windows 虚拟目录配置帮助

ruby-on-rails - Rails + Devise + CouchDB 每个子域一个数据库

amazon-web-services - 无效的重定向 : domain must be added to the authorized domains list despite it being there