对于开发项目我点真正域使用hosts文件为localhost。 我的虚拟主机定义添加到Apache的配置文件。 我的问题是有可能全部重定向“xyz.com”域名为“d:/xampp/htdocs/websites/xyz.com”目录? 这样,我就不会需要添加虚拟主机定义每次。
Answer 1:
您可以使用您的通配符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>
文章来源: apache virtual host definition with regex