htaccess / mod_rewrite / SSL |如果:http off and (basket or order), 301 https, else 301 http
htaccess / mod_rewrite / SSL | If: http off and (basket or order), 301 https, else 301 http
如果用户在篮子里或在订购过程中,我会尝试重定向到 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]
示例 URL 的:
错误:http://www.example.com/basket.html
正确:https://www.example.com/basket.html
第一个 (if) 部分单独使用效果很好 - 但放在一起就很糟糕了!
非常感谢!
你应该这样试试。我觉得你的条件不符合。
# 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]
现在告诉我这对你有用。
如果用户在篮子里或在订购过程中,我会尝试重定向到 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]
示例 URL 的:
错误:http://www.example.com/basket.html 正确:https://www.example.com/basket.html
第一个 (if) 部分单独使用效果很好 - 但放在一起就很糟糕了!
非常感谢!
你应该这样试试。我觉得你的条件不符合。
# 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]
现在告诉我这对你有用。