regex - 仅为特定页面强制使用 SSL

标签 regex apache mod-rewrite ssl https

现在整个站点都配置为在 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/

相关文章:

php - Codeigniter Htaccess 和 URL 重定向问题

.htaccess - .htaccess 文件多长才算太长?

regex - 为什么 perl6 regex ~~ 试图分配给不可变容器?

java - 在哪个行号找到正则表达式匹配项?

apache - mod_rewrite正在重定向浏览器而不是重写

python - 配置 htaccess 以提供静态 django 文件

javascript - 将每个新行的开头与 JavaScript 正则表达式匹配

java - 正则表达式循环依赖性

python - 如何更改 mod_python 使用的 python 版本

php - UTF-8贯穿始终