CodeIgniter routing problem – Showing Homepage but not others

set a Dynamic Base URL in CodeIgniter 4

CodeIgniter routing problem: This is not a very common problem. It comes in few cases but the problem is a problem and finding a solution is very necessary. I have a very useful solution for you and it will definitely help you to solve the Codeigniter 3 & 4 routes problem.

This problem comes when you are using the Nigix Linux server or Apache Linux server. and also your project is in a subdirectory Like: /var/www/example.com/app  or  /var/www/html/app.

 

As you Codeigniter routes working .htaccess file and the problem is also here. but changing anything related to the .htaccess file you need to answer few things.

My CodeIgniter config.php file should like given below:

$base_url   = (isset($_SERVER['HTTPS']) ? "https://" : "http://").$_SERVER['HTTP_HOST'];
$base_url  .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
$config['base_url'] = $base_url;
$config['indexpage’] = “;
$config['uri_protocol’] = 'REQUEST_URI’;

 

My CodeIgniter .htaccess file should be like given below:

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

 

So, if this is all good with your project that means your code and .htaccess file is good and you need to access the server terminal or server, support team.

Also, read about the top richest Indian blogger and how to earn money via blogging.

 

For Apache Linux server:

CodeIgniter routing problem

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/learnphponline.in/app>
   Options Indexes FollowSymLinks
   AllowOverride All
   Require all granted
</Directory>

 

Note:- that you need to update the /var/www/learnphponline.in/public 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.

 

For Nginx, PHP-FPM:

CodeIgniter routing problem

find the file nginx.conf and add this code:

location / {
    # nginx won't display 404, we leave this to Rails
    try_files $uri @passenger;
}

location @passenger {
   passenger_app_root /var/www/learnphponline.in/;
   passenger_document_root /var/www/learnphponline.in/app/;
   passenger_enabled on;
}

 

Summary for the CodeIgniter routing problem

Hope this will help you or at least you get an idea of what issue you are facing. Migration from one server to another or from localhost to live server will create this kind of issue. But if you have proper support from the server team or admin then it will be very easy for you to solve this.

 

Also, read about the Top 10 best freelancing languages or Top 10 programming languages.

Loading

Leave a reply


This site uses Akismet to reduce spam. Learn how your comment data is processed.