[英]Redirecting from HTTPS to HTTP
该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]
简单的方法可能是像这样设置base_url
$config['base_url'] = "https://yoursite.com/";
这将导致所有访问$config['base_url']
-包括redirect()
-的CI函数都使用https。
很少谈论的是base_url()
通过使用第二个参数强制协议的能力。 例如
echo base_url("blog/post/123", 'https');
您可以使用.htaccess强制重定向到https协议。 将其置于现有命令之上。
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.