.htaccess - 用于 SSL 插入 index.php 的 Codeigniter .htaccess 文件

标签 .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 条规则中缺少 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]

关于.htaccess - 用于 SSL 插入 index.php 的 Codeigniter .htaccess 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19563685/

相关文章:

php - 用 PHP 重写 URL

Codeigniter 不创建任何日志文件

codeigniter - 用于多语言文章的 Grocery CRUD

ssl - 我如何在没有自己的邮件服务器的情况下获取 MX 记录?

security - Ephemeral Diffie-Hellman 需要证书吗?

php - htaccess 大写 URL 到小写

apache - 如何删除和避免 htaccess 中的 url 目录

java - 当 android 设备处于 wifi 时,SSLSocket 在 getInputStream 处挂起

php - 在 Wordpress 上使用 .htaccess 重写 URL 以实现 SEO 友好

php - Codeigniter 根据选择的下拉列表 id 显示数据描述