Apache 2.4 AliasMatch 在别名工作时不断返回 404

标签 apache apache2.4 mod-alias

我正在尝试将对与特定模式匹配的 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>

当我调用 apache 时,例如 http://testserver.dev/sitemap.1.xml.gz我收到从服务器返回的 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

有人知道吗?我认为这一定是我忽略的简单问题。

最佳答案

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

首先我添加了这个 LogLevel:

LogLevel 调试别名:trace6

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

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

现在它按预期映射路径。

关于Apache 2.4 AliasMatch 在别名工作时不断返回 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32663239/

相关文章:

php - 带有 mod_vhost_alias 的动态 open_basedir

ubuntu-16.04 - Laravel 流或文件 "/storage/logs/laravel.log"无法打开 : failed to open stream: Permission denied

ssl - wamp服务器中的安装SSL:httpd-ssl.conf中的错误

docker - Apache docker 容器未使用 docker-compose up 启动

regex - mod_alias AliasMatch Regex - 匹配文件夹中除两种模式之外的所有内容?

php - Apache : How to Use Rewrite Engine Inside Alias

ruby-on-rails - OmniAuth 在反向代理设置中使用错误的回调端口

php - 编辑 httpd.conf 以在 mac 上使用 apache 服务器

php - 带有 Apache 和 MySQL mysqli_connect 的 Docker PHP 5.6.23 不是添加了扩展的函数