现在整个站点都配置为在 Apache 中使用 SSL,但我只想对特定页面使用 SSL。比方说:
http://www.mydomain.com/purchase/buy/28
因此 purchase/
中的所有内容(购买、取消、检查等)都必须加密。什么是 Apache 和 mod_rewrite实现该目标的规则?
我试过:
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [L,R]
RewriteCond %{SERVER_PORT} !443
RewriteRule (.*) https://www.mydomain.com/city/ [R]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
但是没有运气 :(.
最佳答案
这应该可以解决问题:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} purchase
RewriteRule ^(.*)$ https://www.mydomain.com/purchase/$1 [R,L]
关于regex - 仅为特定页面强制使用 SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7082513/