【问题标题】:Codeigniter strange issue, Some link with trailing slash work some doesnotCodeigniter 奇怪的问题,一些带有斜杠的链接工作有些没有
【发布时间】:2013-01-10 01:38:51
【问题描述】:

我遇到了奇怪的问题。我有一个 Codeigniter 应用程序,它在我的本地机器上运行良好,但在远程服务器上却不行。以下是场景

  1. 某些带有斜杠的链接有效,但没有斜杠的链接在 Firefox 中显示“连接已重置”错误。

  2. 某些不带斜杠的链接有效,但带斜杠的链接在 Firefox 中显示“连接已重置”错误。

我确信编码没有错误,因为。我认为罪魁祸首是 .htaccess 文件。 以下是我的 .htaccess 文件

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

任何帮助将不胜感激。谢谢!

【问题讨论】:

    标签: .htaccess codeigniter


    【解决方案1】:

    我相信您的问题是缺少“?”在这一行:

    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    

    添加这个“?”直接在'index.php'之后

    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
    

    另外,根据我的经验,我会去掉 RewriteBase 上的尾部斜杠并将其添加到 $config['base_url'] 参数中,然后让 CI 为您完成这项工作:

    $config['base_url'] = 'http://yourwebsite.com/demo/';
    -instead of-
    $config['base_url'] = 'http://yourwebsite.com/demo';
    

    这是我在 CI 中使用了一段时间的 .htaccess 设置,它对我很有帮助:

    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase / # TODO: add a folder name here if the application is not in web root
    
      RewriteCond %{REQUEST_URI} ^system.*
      RewriteRule ^(.*)$ /index.php?/$1 [L]
    
      RewriteCond %{REQUEST_URI} ^application.*
      RewriteRule ^(.*)$ /index.php?/$1 [L]
    
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?/$1 [L]
    </IfModule>
    
    <IfModule !mod_rewrite.c>
      # If we don't have mod_rewrite installed, all 404's
      # can be sent to index.php, and everything works as normal.
      # Submitted by: ElliotHaughin
    
      ErrorDocument 404 /index.php
    </IfModule> 
    

    【讨论】:

      猜你喜欢
      • 2019-04-09
      • 1970-01-01
      • 2022-08-11
      • 2011-08-30
      • 2015-03-24
      • 2020-11-19
      • 2016-07-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多