4

对于开发项目,我使用主机文件将真实域指向 localhost。我将虚拟主机定义添加到 apache 配置文件中。我的问题是可以将所有“xyz.com”域重定向到“d:/xampp/htdocs/websites/xyz.com”目录吗?这样我就不需要每次都添加虚拟主机定义。

4

1 回答 1

12

VirtualHost你可以在你的ServerAlias指令中使用通配符:

<VirtualHost *:80>
  # Official name is example.com
  ServerName example.com

  # Any subdomain *.example.com also goes here
  ServerAlias *.example.com

  DocumentRoot "D:/xampp/htdocs/websites/xyz.com"

  # Then rewrite subdomains into different directories
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^(.*)\.example.com$
  # Use the %1 captured from the HTTP_HOST
  # For example abc.example.com writes to websites/abc.com
  RewriteRule ^(.*)$ "D:/xampp/htdocs/websites/%1.com/$1" [L]
</VirtualHost>
于 2012-06-23T13:25:09.707 回答