Codeigniter: Check and force one page to https://

不想你离开。 提交于 2019-12-24 20:32:44

问题


I want most of my site to be http:// but for a single checkout page to be https://

How can I check and switch the user to https:// so there's no chance they can use it with http://?


回答1:


You can force SSL for specific URLs using .htaccess rules. In this example, if someone visits any of the register/payment directories, they will be redirected to the https:// URL.

RewriteEngine on

RewriteCond %{SERVER_PORT} 80 
RewriteCond $1 ^(register/payment|login)
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R=301,L]

RewriteCond %{SERVER_PORT} 443
RewriteCond $1 !^(register/payment|images|css|javascript|login)
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]

RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L] 

You can change this according to your needs. Hope this helps.




回答2:


You can do it in this way tested and works fine for me

Add this code in your .htaccess file

RewriteEngine On
RewriteCond %{HTTPS} !^on$
RewriteRule ^checkout ? https://myproject.localhost/my_checkout_url [R,L]

Hope it works fine for you also



来源:https://stackoverflow.com/questions/17333335/codeigniter-check-and-force-one-page-to-https

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!