【问题标题】:CodeIgniter always shows 404 errorCodeIgniter 总是显示 404 错误
【发布时间】:2015-05-01 07:16:07
【问题描述】:

我正在使用,并且我已将routes.php 中的默认控制器设置为

$route['default_controller'] = 'home';

我为这个项目设置了Virtual Host,我的.htaccess 看起来像这样

<IfModule mod_headers.c>
   Header set Access-Control-Allow-Origin "*"
 </IfModule>
<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteRule !^[A-Za-z0-9_/\-\.]*$ - [L,R=404]
</IfModule>

<IfModule !mod_rewrite.c>

  ErrorDocument 404 /index.php
</IfModule>

我的 config.php 是这样的

$config['index_page'] = '';

如果默认控制器设置为welcome,则可以正常工作

【问题讨论】:

  • 检查你的控制器文件名是home.php和控制器类是Home。我确定你复制了文件并忘记更改类名。
  • 是否应该在允许字符的重写规则中也检查冒号?
  • 你确定所有的控制器都像 Welcome.php 一样大写
  • 是的,它们都是大写的

标签: codeigniter-3 php .htaccess codeigniter


【解决方案1】:

如果你的文件夹树是这样的:htdocs/codeigniter/

然后在 .htaccess 文件中使用以下代码:

RewriteEngine On
RewriteBase /codeigniter

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]

如果相同,请检查您的 controller 类名和文件名。

【讨论】:

    猜你喜欢
    • 2015-07-04
    • 2014-05-25
    • 2015-12-13
    • 2012-07-12
    • 2016-03-09
    • 2014-08-01
    • 2016-08-15
    • 2012-06-20
    • 1970-01-01
    相关资源
    最近更新 更多