【问题标题】:Codeigniter .htaccess file for SSL inserts index.php用于 SSL 的 Codeigniter .htaccess 文件插入 index.php
【发布时间】:2013-11-03 00:40:01
【问题描述】:

我正在使用以下 .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。有任何想法吗?

谢谢。

【问题讨论】:

    标签: .htaccess codeigniter ssl


    【解决方案1】:

    您的前 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]
    

    【讨论】:

    • 在不同的浏览器中测试以避免301缓存问题。
    【解决方案2】:
    <Directory "/home/test">
        Require all granted
        ***AllowOverride All***
        SSLOptions +StdEnvVars
    </Directory>
    

    在你的apache配置中添加“AllowOverride All”后,它会正常工作。

    问候。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-07
      • 2013-10-21
      • 2019-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-09
      相关资源
      最近更新 更多