单独使用时,下面的每个规则集都可以正常工作。但是,当一起使用时,规则的行为会发生变化。

当单独使用规则集#2时,请求 https:// internal / Security / login 在没有浏览器知识的情况下,Apache将其重写为sapphire / main.php。这是预期的行为。

当两个规则集一起使用时,对前面提到的URL的请求导致Apache发送301重定向到 http://internal/sapphire/main.php?url =安全/登录

为什么Apache会发送此重定向而不是进行内部重写?

# Rule Set # 1
# - Forces all HTTPS requests to HTTP, except for security section requests.
#   Example: request for https://internal/abc/ 
#   -> redirected to http://internal/abc/
RewriteCond %{SERVER_PORT} =443
RewriteCond %{REQUEST_URI} !^/Security($|/.*$)
RewriteRule (.*) http://internal/$1 [R=301,L]

# Rule Set # 2
# - Hands request to CMS - web user does not see this behind-the-scenes rewrite
RewriteRule (.*) sapphire/main.php?url=$1&%{QUERY_STRING} [L]
有帮助吗?

解决方案

L 标志会重新注入已经重写的URL。因此,请尝试分析原始请求的URL:

RewriteCond %{SERVER_PORT} =443
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /Security[/?\ ]
RewriteRule (.*) http://internal/$1 [R=301,L]
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top