在codeigniter中将站点网址http重定向到https

kal*_*iya 5 url https redirect codeigniter http

我想将现有网站重定向到HTTPS.目前在浏览器中,如果URLHTTP开头,那么它将显示错误的网关错误,但我想将网站重定向到HTTPS.

Vik*_*mar 3

尝试以下代码并将这些行放入项目文件夹根部的.htaccess文件(如果不存在则创建):

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Run Code Online (Sandbox Code Playgroud)

并确保您还在 config.php 文件中的 $config['base_url'] 中使用 https 协议,例如

$config['base_url'] = 'https://yourproject.local/';
Run Code Online (Sandbox Code Playgroud)