【发布时间】:2017-10-06 21:59:32
【问题描述】:
webapp 是使用 CodeIgniter 构建的,我使用的是 Cloudflare 的 Flexible SSL。
页面通过 HTTPS 加载,但只要有重定向,页面就会通过 HTTP 加载。从那时起,所有页面都通过 HTTP 提供。
这是一个例子:
public function logout()
{
$this->session->sess_destroy();
redirect('/');
}
注销功能后,所有页面都通过 HTTP 加载。
如何确保页面在重定向后通过 HTTPS 加载?
这是我的 .htaccess 文件的内容:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.myurl.com/$1 [R,L]
【问题讨论】:
-
删除第二个
RewriteEngine On行并将建议的条件/规则放入<IfModule mod_rewrite.c>块中。还要检查APPPATH.'config/config.php'基本网址的值并将 https 也放在那里。 -
为了清楚起见,base url 的值应该是
https://www.myurl.com,对吗? -
用 php
<script>window.location = "http://www.yoururl.com";</script>987654327@ 的 javascript 重定向 -
https://www.myurl.com/ -
@Tpojka 通过保持我的 .htaccess 文件不变,但将我的配置中的基本 URL 更改为 https,该问题已得到解决。谢谢你的建议
标签: php codeigniter ssl https cloudflare