【发布时间】:2019-09-03 07:51:24
【问题描述】:
如何配置 Apache HTTP Server 以重定向每个请求(比如 HTTPS),除非 URL 以特定字符串(比如 /.well-known/)开头,如果是这种情况,如何从目录提供资源? (此案例需要 HTTP 域验证来批准 TLS/SSL 证书)
【问题讨论】:
如何配置 Apache HTTP Server 以重定向每个请求(比如 HTTPS),除非 URL 以特定字符串(比如 /.well-known/)开头,如果是这种情况,如何从目录提供资源? (此案例需要 HTTP 域验证来批准 TLS/SSL 证书)
【问题讨论】:
如果你的配置是这样的:
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
Redirect / https://www.example.com/
</VirtualHost>
那么它将是:
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /http-data/
RedirectMatch "^(?!\/specific_string\/.*$).*" "https://www.example.com$0"
</VirtualHost>
然后,如果 URL 以“/specific_string/”开头,它将提供目录“/http-data/”中的文件。例如“http://example.com/specific_string/index.html”将从目录“/http-data/specific_string/index.html”提供服务。
但任何其他 URL,如“http://example.com/other”,它会重定向到“https://www.example.com/other”。
在 Apache HTTP Server 2.4 上测试。
【讨论】: