重定向http到https不能与AWS EC2和CodeIgniter一起使用

时间:2018-01-31 15:35:01

标签: .htaccess codeigniter amazon-web-services amazon-ec2

在AWS EC2中安装SSL后,会显示以下网址:

...正在重定向到https://www.abcd.com并且工作正常。

http://abcd.com未被重定向。

我该如何解决这个问题?

的.htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^abcd\.com$ [NC]
RewriteRule ^(.*)$ http://www.abcd.com/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 
Options -Indexes

1 个答案:

答案 0 :(得分:0)

试试这个:

RewriteEngine On
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

经过测试here