【问题标题】:Removing index.php from codeigniter-2从 codeigniter-2 中删除 index.php
【发布时间】:2012-06-13 14:14:22
【问题描述】:

我在从 codeigniter-2 中删除 index.php 时遇到问题。 我记得以前也使用过相同的代码,它工作得非常好,但它不适用于 codeigniter-2。

我也检查了documentationthis 的问题,仍然没有任何帮助。

我的.htaccess 代码如下:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

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

【问题讨论】:

  • 我记得以前在 SO 上看到过这种问题。等我找到它!直到那时检查我下面的答案。它会工作
  • 明白了!可能重复:stackoverflow.com/questions/5155333/…有人关闭这个问题,因为我没有足够的代表这样做..

标签: php codeigniter codeigniter-2


【解决方案1】:

/index.php 替换为 /site_folder_name/index.php确保您的服务器支持 mod_rewrite

您的新代码应如下所示:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /site_folder_name/index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /site_folder_name/index.php?/$1 [L]

RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ /site_folder_name/index.php/$1 [L]

【讨论】:

    【解决方案2】:

    试试这个:

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

    【讨论】:

    • 是的,我有这个。没有发布这个以保持问题简短。如果解决了上述问题,这也可以工作
    【解决方案3】:

    你必须为此重写 .htaccess 文件。

    最大服务器使用此功能

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    在 Godaddy 服务器中我必须写这个。有时它适用于 Godaddy 服务器中的上述代码。

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*) index.php?/$1
    

    【讨论】:

      猜你喜欢
      • 2013-04-19
      • 2014-09-20
      • 1970-01-01
      • 1970-01-01
      • 2016-05-14
      • 2014-10-28
      • 2012-06-15
      • 2013-02-27
      • 2012-09-21
      相关资源
      最近更新 更多