使用codeigniter htaccess在整个站点上强制ssl

时间:2013-03-23 16:18:48

标签: php apache .htaccess ssl

我有一个codeigniter网站,我希望它一直强制ssl。我正在使用htaccess文件删除丑陋的index.php

这是我现在拥有的htacces文件的内容......

 RewriteEngine on
 RewriteCond $1 !^(index\.php|static|robots\.txt)
 RewriteRule ^(.*)$ /index.php/$1 [L]

我必须做些什么才能让它始终使用ssl?

谢谢!

2 个答案:

答案 0 :(得分:3)

试试这个:

RewriteEngine On
#RewriteCond %{HTTPS} !=on
RewriteCond %{HTTPS} off
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond $1 !^(index\.php|static|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

答案 1 :(得分:0)

试试这个:


RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?/$1