SSL的Codeigniter .htaccess文件插入index.php

时间:2013-10-24 10:41:42

标签: .htaccess codeigniter ssl

我正在使用以下.htaccess文件将某些网页重定向到https://

RewriteEngine on

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (sale|success|cancel)
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !(static|sale|success|cancel)
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301]

RewriteCond $1 !^(index\.php|resources|robots\.txt|static)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

这是有效的,除了当您转到被重写为https://的页面时,它还会在URL中插入index.php。一切正常,但我希望index.php不要插入。有任何想法吗?

感谢。

2 个答案:

答案 0 :(得分:3)

您在前2条规则中缺少L标记。

您可以使用此代码:

RewriteEngine on

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (sale|success|cancel) [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !(static|sale|success|cancel) [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond $1 !^(index\.php|resources|robots\.txt|static) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

答案 1 :(得分:0)

<Directory "/home/test">
    Require all granted
    ***AllowOverride All***
    SSLOptions +StdEnvVars
</Directory>

在您的apache配置中添加“AllowOverride All”后,它将正常运行。

问候。