代码之家  ›  专栏  ›  技术社区  ›  Joseph

找不到CodeIgniter 404页,但为什么?

  •  18
  • Joseph  · 技术社区  · 15 年前

    我使用CodeIgniter的两个应用程序(一个公共和管理应用程序)。

    /admin
    /admin/.htaccess
    /admin/index.html
    /application
    /application/admin
    /application/public
    /system
    .htaccess
    index.php
    

    /admin/.htaccess文件如下所示:

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

    $system_folder = "../system";
    $application_folder = "../application/admin"; (this line exists of course twice)
    

    以及/application/admin/config/路由.php包含以下内容:

    $route['default_controller'] = "welcome";
    $route['admin'] = 'welcome';
    

    当我调用域/管理员时,我得到一个404页未找到错误。当我调用Domain/admin/welcome时,一切正常。在调试日志中,我得到以下错误消息:

    DEBUG - 2010-09-20 16:27:34 --> Config Class Initialized
    DEBUG - 2010-09-20 16:27:34 --> Hooks Class Initialized
    DEBUG - 2010-09-20 16:27:34 --> URI Class Initialized
    ERROR - 2010-09-20 16:27:34 --> 404 Page Not Found --> admin
    

    有什么想法吗?我做错什么了? 谢谢 C。

    8 回复  |  直到 15 年前
        1
  •  14
  •   Joseph    15 年前

    问题的原因是服务器使用FastCGI运行PHP。

    $config['uri_protocol'] = "REQUEST_URI";
    

    一切正常。

        2
  •  12
  •   Amin Balogun    8 年前

    你可以尝试两种方法中的一种或两者的结合。

    1. 如果你没有对你的路线做任何改变,出于某种奇怪的原因,你可能不得不在你的网址中加入大写字母。e、 如果你的控制器是'Mycontroller.php'其中有一个名为'testfunc'的函数,则您的url如下所示: http://www.yourdomain/index.php/Mycontroller/testfunc ". 注意大写字母。(我假设您没有添加htaccess文件来删除'索引.php'部分。如果有,只需将其从url中删除即可。)

    我希望这能帮助别人

        3
  •  9
  •   Community CDub    8 年前

    我的codeigniter应用程序在localhost/WAMP中运行良好,但在推送到awsec2实例时无法路由并产生404notfound错误。我的问题从我的回答中解决了 HERE htaccess works in localhost but doesn't work in EC2 instance

    (路由到我的管理页面) {domain}/admin正在生成404

    /etc/httpd/conf/httpd.conf 文件需要修改。

    -在“DocumentRoot”/var/www/html”“(2个位置)的每个实例之后,“AllowOverride None”需要更改为“AllowOverride All”。

    从AWS仪表板重新启动EC2实例。

    {domain}/admin现在可以访问并按预期工作。

        4
  •  7
  •   DevYuan    8 年前
    1. 将控制器名称的第一个字母改为大写。

    例如:

    你的控制器名是你的控制器

    http://example.com/index.php/YourController/method

    http://example.com/index.php/yourcontroller/method

        5
  •  2
  •   MAK    13 年前

    我们必须在服务器端以小写形式给出控制器名称

    $this->class = strtolower(__CLASS__);
    
        6
  •  1
  •   treeface    15 年前

    我觉得你的文件夹/文件结构有点奇怪。我不太明白你是怎么安排的。

    $system_folder = "../system";
    $application_folder = "../application/admin"; (this line exists of course twice)
    

    你所说的存在的地方(/admin)/索引.php…还是说/admin/application/config?)让我挠头。在顶层有admin/application/admin和一个系统文件夹?

        7
  •  1
  •   Antony P.    8 年前

    我在迁移到一个新环境后也遇到了同样的问题,只是服务器没有运行mod\u rewrite

    快速 sudo a2enmod rewrite 然后 sudo systemctl restart apache2

    问题解决了。。。

    感谢@fanis,他在对这个问题的评论中指出了这一点。

        8
  •  1
  •   Dan Linh    5 年前

    如果您还没有添加,请添加。 您可以将默认内容放入.htaccess文件,如下所示。

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    #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
    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>
    
        9
  •  0
  •   Max    9 年前

    在我的情况下,我是用它在 localhost 忘了换衣服 RewriteBase 在里面 .htaccess .

        10
  •  0
  •   Nicolas Gervais kev    5 年前

    如果应用程序位于子文件夹中,则目录和URL中的文件夹名称必须相同 (区分大小写) .

        11
  •  0
  •   NAVNEET CHANDAN    5 年前

    确保类名与控制器名相同。例如。, 如果您的控制器名称为设置.php,必须像这样扩展控制器。

    class Settings extends CI_Controller
    {
    // some actions like...
         public function __construct(){
         // and so and so...
         }
    }
    
        12
  •  0
  •   Sanath L S    4 年前

    sudo nano /etc/apache2/apache2.conf 
    

    转到172号线换车

    <Directory /var/www/>
            Options Indexes FollowSymLinks
            AllowOverride None
            Require all granted
    </Directory>
    

    <Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    

    sudo systemctl restart apache2