重定向指令是否覆盖配置的别名

rob*_*tor 1 apache redirect mod-alias virtualhost httpd.conf

我正在将 apache 2.4 (docker) 设置为反向代理,以将不同的子域分发到不同的 docker 服务。我使用该指令将 http 请求重定向到 https Redirect。然而,一个特定的 URL 路径(域后面的部分)不应被重定向为 https,而应与来自特定目录的文件一起提供。我试图使用该Alias指令来完成此操作,但这不起作用。

我假设它Redirect会覆盖Alias. 真的吗?如果是这样的话,我该如何实现我的目标呢?

<VirtualHost *:80>

    ServerName service.example.com

    Alias /exception/ /var/www/exception
    Redirect permanent / https://service.example.com/

</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

我预计这会起作用,但事实并非如此。

Dus*_*jic 5

来自mod_alias 文档

首先,所有重定向都会在别名处理之前处理,因此与 Redirect 或 RedirectMatch 匹配的请求永远不会应用别名。其次,别名和重定向按照它们在配置文件中出现的顺序进行处理,第一个匹配优先。

要确保/exception/不匹配,请使用RedirectMatch允许正则表达式模式:

RedirectMatch permanent "^/(?!exception/)(.*)" "https://service.example.com/$1"
Run Code Online (Sandbox Code Playgroud)