Codeigniter:检查并强制将一个页面强制为https://

时间:2013-06-27 01:57:09

标签: php codeigniter .htaccess redirect https

我希望我的大部分网站都是http://但是对于单个结帐页面是https://

如何检查并将用户切换为https://因此他们无法将其与http://一起使用?

2 个答案:

答案 0 :(得分:1)

您可以使用.htaccess规则为特定网址强制使用SSL。在此示例中,如果有人访问任何注册/付款目录,他们将被重定向到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] 

您可以根据需要进行更改。希望这会有所帮助。

答案 1 :(得分:1)

你可以用这种方式测试并且对我来说很好用

.htaccess文件中添加此代码

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

希望它也适合你