单页的HTTP到HTTPS

时间:2014-11-22 17:26:28

标签: php .htaccess

我想应用重写规则,将付款页面http重定向到https。我希望https仅用于付款页面,如果用户点击主页选项卡,它应该转到http不在https

示例:

http://example.com/index.php

http://example.com/about.php

https://example.com/payment.php

http://example.com/home.php

1 个答案:

答案 0 :(得分:2)

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{HTTPS} off
  RewriteCond %{REQUEST_URI} ^/payment\.php$ [NC]
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  RewriteCond %{HTTPS} on
  RewriteCond %{REQUEST_URI} !^/payment\.php$ [NC]
  RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>