codeigniter,在特定页面上强制ssl



我很难将https(ssl)强制到codeigiiter框架上的特定页面。我尝试了很多方法,但都没有成功。对我来说,唯一有效的方法是将$config['base_url']网站链接更改为以https开头,而不是以http开始。结果是,所有链接都设置为ssl(整个站点),这毫无意义,因为我不需要在任何地方使用ssl。我在登录页面中使用了一些php代码,但这带来了一些麻烦,所以我放弃了它。

我想知道这是否是一个好方法如何做到这一点,有什么想法吗?

谢谢,

您需要在.htaccess上添加Condition,以使SSL端口仅适用于选定的URL。

以下是如何进行的示例

RewriteEngine on
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} controller/function
RewriteRule ^(.*)$ https://www.yourdomain.com/controller/function[R=301,L]
RewriteCond %{SERVER_PORT} 443 
RewriteCond %{REQUEST_URI} controller/function
RewriteRule ^(.*)$ https://www.yourdomain.com/controller/function[R=301,L]
RewriteCond $1 !^(index.php|images|robots.txt)
RewriteRule ^(.*)$ index.php/$1 [L] 

p.S:您的base_url必须在配置文件中设置为“/”。查看更多信息http://codeigniter.com/wiki/SSL_Handling

最新更新