.htaccess - htaccess/mod_rewrite/SSL |如果 : http off and (basket or order), 301 https,否则 301 http

标签 .htaccess mod-rewrite redirect ssl https

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

相关文章:

php - .htaccess 的相对 URL

PHP $_SERVER ["PATH_INFO"] url 中没有 index.php 时不返回信息(htaccess url 重写)

apache - apache conf <Location/> 中的 mod_rewrite 导致 .htaccess 文件中的重写不起作用?

php - 如何让 SSL+mod_rewrite+Zend Framework MVC 一起工作?

javascript - 如何在 jquery 帖子的回调中重定向

php - 为什么要避免使用 LAMP 托管的 Python 的 CGI?

http - apache httpd - RewriteCond SERVER_NAME 不等于 SERVER_ADDR

linux - 301重定向网址

javascript - 切换 Node.js 应用程序时 localhost:3000 不会改变

windows - 在 Win XP 命令行中同时将输出重定向到多个文件和标准输出