Problem with codeigniter routing

Posted March 9, 2020 4.8k views
PHP Frameworks

I have this website:
The homepage is working fine. But no one of the other pages works :(

My config.php:
$config[‘baseurl’] = “”;
page’] = “;
$config['uri_protocol’] = 'AUTO’;

My routes.php:
$route['default_controller’] = "home”;
$route['admin’] = “admin/login”;
$route['apple’] = “home/apple”;
$route['xiaomi’] = “home/xiaomi”;
$route['samsung’] = “home/samsung”;

My .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUESTFILENAME} !-f
RewriteCond %{REQUEST
RewriteCond $1 !^(index.php|assets|upload|robots.txt|..css)
RewriteRule ^(.
)$ index.php?/$1 [L]

Rewrite mod is enabled on VPS.

It was working fine in other hosting, but not on DO.
When I open the website home, it’s ok. But when trying to open other pages (like “apple”, “samsung”), I got 404 error.

What can I do?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi there @rickfontoura,

I believe that you need to enable AllowOverride in order for your .htaccess to take effect.

To do that you need to add the following in your Vhost:

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

Note that you need to update the /var/www/ part to match your document root.

Then run a config test and restart Apache.

After that the rules that you have in your .htaccess file would take effect.

Hope that this helps!