从 HTTPS 重定向到 HTTP

Redirecting from HTTPS to HTTP

Web 应用程序是使用 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?/ [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/ [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]
</IfModule>
 <IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule> 

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.myurl.com/ [R,L]

简单的方法可能是像这样设置 base_url

$config['base_url'] = "https://yoursite.com/";

这将导致所有 CI 访问 $config['base_url'] 的函数(包括 redirect())使用 https。

很少有人谈论 base_url() 通过使用第二个参数来强制执行协议的能力。例如

echo base_url("blog/post/123", 'https'); 

您可以使用 .htaccess 强制重定向到 https 协议。 把它放在你现有的命令之上。

RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/ [R,L]