【问题标题】:Apache 2.4 AliasMatch keeps returning 404 when Alias works当 Alias 工作时,Apache 2.4 AliasMatch 不断返回 404
【发布时间】:2015-12-16 06:22:07
【问题描述】:

我正在尝试将与特定模式匹配的 Apache 2.4 虚拟主机 (Wampserver 2.5) 的调用重定向到我的 DocumentRoot 之外的目录。这是我的 .conf 文件中的相关代码:

<VirtualHost *:80>
    ServerName testserver.dev
    DocumentRoot "D:\Path\to\webserver\public\build"

    RewriteEngine On
    LogLevel alert rewrite:trace6

    # Statement below results in 404
    AliasMatch "^/sitemap.\d+.xml.gz$" "D:\Path\to\webserver\private\index.php"
</VirtualHost>

当我调用 http://testserver.dev/sitemap.1.xml.gz 之类的 apache 时,我收到了从服务器返回的 404。据我所知,匹配实际上是有效的,所以我假设目录路径配置错误?如果我对其进行硬编码并仅使用普通的 Alias 它会按预期工作:

# This works below
Alias /sitemap.1.xml.gz "D:\Path\to\webserver\private\index.php"

不知道我做错了什么。我启用了日志记录,这就是错误日志中显示的内容:

init rewrite engine with requested uri /sitemap.1.xml.gz
pass through /sitemap.1.xml.gz

并且在访问日志中针对不工作的请求

"GET /sitemap.1.xml.gz HTTP/1.1" 404 304

有人知道吗?我认为这必须是我忽略的一些简单的事情。

【问题讨论】:

    标签: apache apache2.4 mod-alias


    【解决方案1】:

    在意识到我没有看到 Alias 日志记录后,我发现了这一点。

    首先我添加了这个 LogLevel:

    LogLevel debug alias:trace6

    这让我看到当它试图替换正则表达式匹配项(我没有使用)时,反斜杠正在我的目标目录中被删除。由于我在 Windows 上,因此我将路径更改为以下内容:

    D:/Path/to/webserver/private/index.php

    它现在按预期映射路径。

    【讨论】:

      猜你喜欢
      • 2020-07-04
      • 2019-05-16
      • 1970-01-01
      • 2018-08-30
      • 2018-09-14
      • 2016-01-31
      • 2015-06-04
      • 1970-01-01
      • 2018-01-21
      相关资源
      最近更新 更多