gpt4 book ai didi

regex - apache虚拟主机定义与正则表达式

转载 作者:行者123 更新时间:2023-12-01 09:04:14 24 4
gpt4 key购买 nike

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

最佳答案

您可以在VirtualHostServerAlias指令中使用通配符:

<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>

关于regex - apache虚拟主机定义与正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11169843/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com