bki*_*inc 3 regex apache vhosts
对于开发项目,我使用hosts文件将实际域指向localhost.我将虚拟主机定义添加到apache配置文件.我的问题是可以将所有"xyz.com"域重定向到"d:/xampp/htdocs/websites/xyz.com"目录吗?这样我每次都不需要添加vhost定义.
你可以在你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>
Run Code Online (Sandbox Code Playgroud)