单独使用时,下面的每个规则集都可以正常工作。但是,当一起使用时,规则的行为会发生变化。
当规则集#2单独使用时,Apache将对https://internal/Security/login的请求重写为sapphire / main.php,而浏览器不知道。这是预期的行为。
当两个规则集一起使用时,对前面提到的URL的请求导致Apache向http://internal/sapphire/main.php?url=Security/login发送301重定向。
为什么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]
答案 0 :(得分:1)
L 标志会重新注入已经重写的URL。因此,请尝试分析原始请求的URL:
RewriteCond %{SERVER_PORT} =443
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /Security[/?\ ]
RewriteRule (.*) http://internal/$1 [R=301,L]