CodeIgniter routing not working

I am having problems with my routing. My default controller (mysite.com) will work, but if I try something else (like mysite.com/dashboard), it will go to 404 server, not CodeIgniter. This is very confusing since at the moment I have only 2 paths in the routes.php file. Below are the sections without comment in the routes.php file:

$route['404_override'] = '';

$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';

My controller is located in /application/controllers/pages.php.

I do not think this is a .htaccess problem (since it can get to the controller by default), but here is my .htaccess file:

RewriteEngine On
RewriteCond $1 !^(index\.php|styles|scripts|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

#<IfModule mod_gzip.c>
#    mod_gzip_on       Yes
#    mod_gzip_dechunk  Yes
#    mod_gzip_item_include file      \.(html?|txt|css|js|php|pl)$
#    mod_gzip_item_include handler   ^cgi-script$
#    mod_gzip_item_include mime      ^text/.*
#    mod_gzip_item_include mime      ^application/x-javascript.*
#    mod_gzip_item_exclude mime      ^image/.*
#    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
#</IfModule>

Edit

Here is the page controller:

<?php

        class Pages extends CI_Controller {

        public function __construct()
        {       
                //Construct it parent
            parent::__construct();

            //Check login
            //$this->load->model('pages_model');
        //$this->pages_model->getLoginStatus();

    }


    public function view($page = 'dashboard')
    {

        //If the file doesn't exist
        if ( ! file_exists('/var/www/vhosts/mysite/httpdocs/library/application/views/pages/'.$page.'.php'))
        {
            // Whoops, we don't have a page for that!
            show_404();
        }       

        $data['title'] = ucfirst($page); // Capitalize the first letter

        //Load all necessary views
        $this->load->view('templates/head', $data); 
        $this->load->view('templates/header', $data);
        $this->load->view('pages/'.$page, $data);
        $this->load->view('templates/footer', $data);

    }

}

?>
+3
source share
3 answers

​​ , .htaccess

+4

htaccess, :

Options -Indexes
Options +FollowSymLinks

# Set the default file for indexes
DirectoryIndex index.php

<IfModule mod_rewrite.c>

    # activate URL rewriting
    RewriteEngine on


    # do not rewrite links to the documentation, assets and public files
    RewriteCond $1 !^(images|assets|uploads|captcha)

    # do not rewrite for php files in the document root, robots.txt or the maintenance page
    RewriteCond $1 !^([^\..]+\.php|robots\.txt|maintenance\.html)

    # but rewrite everything else
    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.

    ErrorDocument 404 index.php

</IfModule>  

, config.php:

  $config['index_page'] = '';
+2

I recently updated the PHP version on the server from 7.0 to 7.2. However, my CodeIgniter Routing stopped working after that. All requests returned 300 errors in the browser console.

I solved the problem by switching to PHP 7.0.

0
source

All Articles