Search code examples
codeignitercodeigniter-4

CodeIgniter 4 routes not working properly


I just got into CI4 from a CI3 background but I'm finding it difficult to get routes to display the appropriate view. Even though I have written the code in the controller properly to load a view, it always returns index.php no matter what instead of the correct view even when I enter a non-existent route. The 404 page doesn't show either.

Here's my controller code:

<?php

namespace App\Controllers;

class Shop extends BaseController
{
    public function index()
    {
        return view('shop');
    }
}

Here's the result I get on the browser: Result


Solution

  • SOLVED!

    I realized the problem was that apache's rewrite module was disabled by default by running sudo a2query -m rewrite so I had to enable it by running sudo a2enmod rewrite. If you're having this same issue please make sure your rewrite module is enabled.