To remove the index.php from CodeIgniter URLs on Nginx, you need to modify your Nginx configuration file as follows:

  1. Open your Nginx configuration file. This is usually located in /etc/nginx/nginx.conf or in a file located in /etc/nginx/conf.d/.

  2. Locate the location / block in your configuration file.

  3. Add the following lines inside the location / block:

try_files $uri $uri/ /index.php?$query_string;
  1. Add the following lines after the location / block:
location ~ \.php$ { fastcgi_pass unix:/run/php/php7.4-fpm.sock; # Use the correct PHP version fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
  1. Save the configuration file and restart Nginx to apply the changes.
sudo systemctl restart nginx

With these changes, Nginx should now be able to route requests to CodeIgniter without including the index.php in the URL.

Have questions or queries?
Get in Touch