使 Alias 免受 RewriteRule 的影响

使 Alias 免受 RewriteRule 的影响

我有以下 Apache 配置:

<VirtualHost *:80>

    Alias "/.well-known" "/var/www/example.com/.well-known"

    RewriteEngine On

    <If "%{HTTP_HOST} == 'example.com'">
        RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    </If>

    <ElseIf "%{HTTPS} != 'on'">
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    </ElseIf>

</VirtualHost>

我想要Alias免除 HTTPS 重定向,即http://example.com/.well-known/x应该返回文件/var/www/example.com/.well-known/x。目前,它正在按照RewriteRules以下方式重定向到 HTTPS。

我怎样才能免除Alias重定向?

答案1

<If "%{HTTP_HOST} == 'example.com' && !(${REQUEST_URI -strcmatch '/.well-known/*')" >
    RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</If>

<ElseIf "%{HTTPS} != 'on' && !(${REQUEST_URI -strcmatch '/.well-known/*')">
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</ElseIf>

相关内容