CodeIgniter 404 Page Not Found, but why?

前端 未结 11 2347
Happy的楠姐
Happy的楠姐 2020-12-11 14:48

I am using CodeIgniter for two applications (a public and an admin app). The important elements of the document structure are:

/admin
/admin/.htaccess
/admin         


        
相关标签:
11条回答
  • 2020-12-11 15:16

    we have to give the controller name in lower cases in server side

    $this->class = strtolower(__CLASS__);
    
    0 讨论(0)
  • 2020-12-11 15:16

    If you installed new Codeigniter, please check if you added .htaccess file on root directory. If you didn't add it yet, please add it. You can put default content it the .htaccess file like below.

    <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>
    
    0 讨论(0)
  • 2020-12-11 15:17

    You could try one of two things or a combination of both.

    1. Be sure that your controller's name starts with a capital letter. eg "Mycontroller.php"
    2. If you have not made any changes to your route, for some strange reason, you might have to include capital letters in your url. e.g if your controller is 'Mycontroller.php' with a function named 'testfunc' inside it, then your url will look like this: "http://www.yourdomain/index.php/Mycontroller/testfunc". Note the capital letter. (I'm assuming you haven't added the htaccess file to remove the 'index.php' part. If you have, just remove it from the url.)

    I hope this helps someone

    0 讨论(0)
  • 2020-12-11 15:17

    It happens cause of multiple reasons but the answer missing above there's the "className" while extending your controller.

    Make sure your class name is the same as your controller name is your controllers. e.g., If your controller name is Settings.php, you must extend the controller like.

    class Settings extends CI_Controller
    {
    // some actions like...
         public function __construct(){
         // and so and so...
         }
    }
    
    0 讨论(0)
  • 2020-12-11 15:19

    If your application is in sub-folder then the Folder name in directory and URL must be same (case-sensitive).

    0 讨论(0)
  • 2020-12-11 15:24

    The cause of the problem was that the server was running PHP using FastCGI.

    After changing the config.php to

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

    everything worked.

    0 讨论(0)
提交回复
热议问题