我很难尝试强制 https (ssl) 到 codeigniter 框架上的特定页面。我尝试了很多方法,但都没有用。对我有用的唯一方法是将 $config['base_url'] 站点链接更改为以 https 而不是 http 开头。结果是所有链接都设置为 ssl(整个站点),这是没有意义的,因为我不需要在任何地方都使用 SSL。我在登录页面中使用了一些 php 代码,但这造成了一些麻烦,所以我放弃了。
我想知道这是否是一个好方法,如何做到这一点,有什么想法吗?
谢谢,
最佳答案
您需要在 .htaccess
上添加条件,使 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
关于codeigniter,在特定页面上强制使用 ssl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9972264/