【问题标题】:htaccess / mod_rewrite / SSL | If: http off and (basket or order), 301 https, else 301 httphtaccess / mod_rewrite / SSL | If: http off and (basket or order), 301 https, else 301 http
【发布时间】:2015-03-05 23:13:27
【问题描述】:

如果用户在购物篮中或在订购过程中,我会尝试重定向到 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

第一个(如果)部分单独效果很好 - 但放在一起就很糟糕!

非常感谢!

【问题讨论】:

    标签: .htaccess mod-rewrite redirect ssl https


    【解决方案1】:

    你应该这样试试。我不认为你的条件符合。

    # 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]
    

    现在让我知道这对你有用。

    【讨论】:

    • 谢谢,但很遗憾还是和以前一样!如果单独工作,但与 elseif 块结合使用它不再工作。
    • 清除浏览器缓存或在其他浏览器中尝试。我知道这应该有效。我已经测试过了。
    • 好吧,你是对的!它可以工作 - 但不能与我的其他 RewriteRules 一起工作,而且我不知道他们会如何产生任何问题 - 因为 L 标志。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-10
    • 2014-11-18
    • 2019-02-04
    • 2019-08-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多