如果用户在篮子里或在订购过程中,我会尝试重定向到 https(并返回)。
我尝试了很多 - 但它不起作用:
# if ssl off and basket|order -> https
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (?:basket|order)
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]
# elseif ssl on and !basket|order -> http
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !(?:basket|order)
RewriteRule ^ http://www.example.com%{REQUEST_URI} [R=301,L]
示例网址:
错误:http://www.example.com/basket.html 正确:https://www.example.com/basket.html
第一个(如果)部分单独使用效果很好 - 但放在一起就很糟糕了!
非常感谢!
最佳答案
你应该这样试试。我认为您的条件不匹配。
# if ssl off and basket|order -> https
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/(basket|order).html [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]
# elseif ssl on and !basket|order -> http
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/(basket|order).html [NC]
RewriteRule ^ http://www.example.com%{REQUEST_URI} [R=301,L]
现在让我知道这对您有用。
关于.htaccess - htaccess/mod_rewrite/SSL |如果 : http off and (basket or order), 301 https,否则 301 http,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28879791/