【问题标题】:How to create Virtual Host from Apache .htaccess?如何从 Apache .htaccess 创建虚拟主机?
【发布时间】:2011-09-10 15:54:30
【问题描述】:

我在 Windows(本地服务器)中使用 Apache Friends XAMPP。我在这样的 Apache 配置目录中的 httpd-vhosts.conf 中设置了虚拟主机

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName test.example.com
    DocumentRoot "E:\xampp\htdocs\example"
</VirtualHost>

当我浏览 URL 时效果很好

http://test.example.com

是否可以从 Apache .htaccess 动态创建虚拟主机?

【问题讨论】:

    标签: apache .htaccess mod-rewrite url-rewriting virtualhost


    【解决方案1】:

    这似乎是不可能的。因为您的.htaccess 仅在您的主机被httpd.confapache2.conf 等服务器的根配置文件解析后使用。

    简单来说,www目录或其子目录中的.htaccess只有在根配置文件处理完后才会被处理。

    我的意思是你输入http://host.name,apache 会找到目的地并在需要时使用主机上的.htaccess 文件来执行一些操作。

    【讨论】:

      【解决方案2】:

      VirtualHost 的上下文必须是 server config。请参阅Apache docs

      这意味着该指令可能是 在服务器配置文件中使用 (例如,httpd.conf),但不在任何 要么 容器。不允许进入 .htaccess 文件。

      (Directive Dictionary)

      【讨论】:

        猜你喜欢
        • 2022-09-27
        • 2013-02-17
        • 1970-01-01
        • 2019-12-04
        • 1970-01-01
        • 2012-09-05
        • 2016-06-15
        • 2016-11-26
        • 2014-08-23
        相关资源
        最近更新 更多