我希望确保我的应用程序中的少量URL总是通过SSL提供的;其余的应该始终通过HTTP提供。
我目前的mod_rewrite规则如下:
RewriteCond %{HTTPS} off
RewriteRule ^/?account.html$ https://example.com/account.html [L]
RewriteRule ^/?checkout.html$ https://example.com/checkout.html [L]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !/account.html$
RewriteCond %{REQUEST_URI} !/checkout.html$
RewriteRule (.*) http://example.com/$1 [L]每个RewriteCond中的第一个文件工作正常(本例中为account.html)。第二个文件不工作--服务器正在“以一种永远不会完成的方式重定向”。
对如何使这件事奏效有什么想法吗?在生产中会有超过2个SSL的URL,可能是7-10个.
谢谢
发布于 2014-09-05 15:28:49
必须使用R标志重定向url。
RewriteEngine On
# redirect account.html or checkout.html (if http) to https
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/(account|checkout)\.html$ [NC]
RewriteRule ^ https://%{HTTP_HOST}/%1.html [R,L]
# redirect other urls (if https) to http
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/(account|checkout)\.html$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R,L]注意:我使用了R标志,默认情况下它执行302重定向。可以在[R,L]工作时用[R=301,L]代替它(301重定向是永久的重定向,并由浏览器缓存)
https://stackoverflow.com/questions/25689149
复制相似问题