【问题标题】:Using htaccess to remove codeigniter index.php in a subdirectory使用 htaccess 删除子目录中的 codeigniter index.php
【发布时间】:2011-10-09 14:26:51
【问题描述】:

我正在尝试从我的 CI url 中删除 index.php,但是按照说明操作它似乎不起作用。

我有一个在子目录中运行的 codeigniter 安装。在路由配置中设置了一个名为 main 的默认控制器,以及另一个名为“create”的控制器。默认运行良好,但转到 /create 会返回 324 错误,提示未收到数据。我的 htaccess 看起来像这样:

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /

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

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

</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

【问题讨论】:

  • 您的 apache error.log 输出将有助于解决您的问题。

标签: .htaccess codeigniter subdirectory


【解决方案1】:

这就够了:

<IfModule mod_rewrite.c>
RewriteEngine On

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

【讨论】:

  • 获胜者是……这个。
  • 并且不要忘记更改stackoverflow.com/a/14807463/1537413中提到的apache配置
【解决方案2】:

这是我使用的。我的 CodeIgniter 也在子目录中运行。

RewriteEngine on
RewriteCond $1 !^(index\.php|images|swf|uploads|js|css|robots\.txt)
RewriteRule ^(.*)$ /ci/index.php/$1 [L]

【讨论】:

  • 我一直在寻找合适的 mod_rewrite 好几个小时,而这个终于为我工作了!我所要做的就是将ci/ 更改为mysubfolder/
【解决方案3】:

.htaccess 添加:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

进入application/config/config.php并清除索引页配置值:

// Old

$config['index_page'] = "index.php";

// New

$config['index_page'] = "";

解决了我的问题希望其他人也... :)

【讨论】:

  • 我尝试了 codeigniter 用户指南中的代码,但没有成功,但现在它就像魔术一样工作,谢谢先生
【解决方案4】:

有时需要开启重写模块,运行“apache2 enable module rewrite”:

sudo a2enmod rewrite

您需要重新启动网络服务器以应用更改:

sudo service apache2 restart

然后按照索菲亚的回答。

【讨论】:

    【解决方案5】:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule . index.php [L]

    对于ubuntu

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-19
      • 2019-04-06
      • 2015-03-09
      • 2013-01-08
      • 1970-01-01
      • 2016-05-13
      • 1970-01-01
      • 2013-03-07
      相关资源
      最近更新 更多