如果在https中访问URL,并且仅当该参数不存在时,我需要向URL添加一个参数(我不需要检查参数值(。
-
示例1:不应该做任何事情,因为url正在http 中被访问
原始URL:http://example.com
最终URL:http://example.com -
示例2:Apache需要重定向到https://example.com?parameterName=parameterValue
原始URL:https://example.com
最终URL:https://example.com?parameterName=parameterValue -
示例3:不应该做任何事情,因为url在https中,并且包含参数"parameterName"(这是为了防止无限循环(
原始URL:https://example.com?parameterName=parameterValue
最终URL:https://example.com?parameterName=parameterValue
到目前为止我尝试过的:
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^parameterName$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}%parameterName=parameterValue
编辑1:如果我删除"RewriteCond%{HTTPS}on"条件,则该规则似乎正在执行。参数没有正确附加,但至少规则正在执行。
现在我需要理解为什么在HTTPS中不执行该规则。
我在谷歌上搜索了一下,发现一些帖子说AllowOverride必须改为AllowOverrideAll。
我在httpd-conf文件中更新了下面的行,但行为没有改变:
从:AllowOverride无
到AllowOverride全部
下面的代码完成了我需要的:
RewriteCond %{HTTPS} on
RewriteCond %{QUERY_STRING} !.*parameterName.*
RewriteRule /myapplicationpath?(.*) /myapplicationpath?parameterName=parameterValue&%{QUERY_STRING} [R]