Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex htaccess强制特定查询参数上的https,并一般删除www_Regex_Apache_.htaccess_Mod Rewrite_Https - Fatal编程技术网

Regex htaccess强制特定查询参数上的https,并一般删除www

Regex htaccess强制特定查询参数上的https,并一般删除www,regex,apache,.htaccess,mod-rewrite,https,Regex,Apache,.htaccess,Mod Rewrite,Https,谢谢你在这方面的帮助。我试图在url中的查询参数标识的特定视图上强制使用https。但该规则似乎与其他强制删除www子域的规则相冲突 My.htaccess当前看起来如下所示: RewriteCond %{QUERY_STRING} !(^|&)param=(foo)(&|$) RewriteCond %{HTTPS} on RewriteRule ^index\.php$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R] RewriteCond

谢谢你在这方面的帮助。我试图在url中的查询参数标识的特定视图上强制使用https。但该规则似乎与其他强制删除www子域的规则相冲突

My.htaccess当前看起来如下所示:

RewriteCond %{QUERY_STRING} !(^|&)param=(foo)(&|$)
RewriteCond %{HTTPS} on
RewriteRule ^index\.php$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R]

RewriteCond %{QUERY_STRING} (^|&)param=(foo)(&|$)
RewriteCond %{HTTPS} off
RewriteRule ^index\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]

RewriteCond %{HTTP_HOST} ^www\.
RewriteCond %{HTTPS}s ^on(s)|off
RewriteCond http%1://%{HTTP_HOST} ^(https?://)(www\.)?(.+)$
RewriteRule ^ %1%3%{REQUEST_URI} [R=301,L]

但是,这会导致相关页面上出现重定向循环。

尝试在前两条规则中使用
请求

RewriteCond %{THE_REQUEST} !/index\.php\?param=foo[&\s]
RewriteCond %{HTTPS} on
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R]

RewriteCond %{THE_REQUEST} /index\.php\?param=foo[&\s]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]

RewriteCond %{HTTP_HOST} ^www\.
RewriteCond %{HTTPS}s ^on(s)|off
RewriteCond http%1://%{HTTP_HOST} ^(https?://)(www\.)?(.+)$
RewriteRule ^ %1%3%{REQUEST_URI} [R=301,L]

请确保清除浏览器缓存以测试此更改。

这将不再在相关页面上强制使用https。我希望强制使用https的url如下:是-抱歉,这只是为了说明问题。我在您的代码版本中使用了正确的参数。https仍然不是强制的。它将从所有URL中删除www。第一种方法是,如果查询参数匹配,则强制https重定向到http。第二种则相反:如果https处于关闭状态且查询参数匹配,则强制https打开。第三种方法只需要考虑url中有www的情况,并重定向到不让www保留原始请求的http或https。我最初的规则是独立工作的,但不是一起工作的。让我们一起来吧。