Remove index.php for CI on nginx

Nginx server configuration for removing the index.php from CodeIgniter wbesite URL.

This quick tutorial will guide you for Nginx server configuration for removing the index.php from URL for websites developed on CodeIgniter server.

For removing the index.php from URL as the first step this needs to be removed from the URLs generated by CodeIgniter and then we need to do the mapping in Nginx to serve all the requests through index.php file even though there is no index.php in the request URI path.

As the first step please open the config.php in application/config path of the codeigniter application and remove the index.php from the index page.

$config['index_page'] = '';
Also set the URL suffix which you want to use for your dynamic pages.
$config['url_suffix'] = '.html';
After that go to your nginx configuration directory (etc/nginx/sites-available) and create a config file with your website domain name. (Example: Please include similar configuration below inside your site. Also note that this is for nginx server in linux. For windows the handling the php using Fast CGI processing will be different but mapping the html files through index.php file will be same.
    root            /opt/www/$server_name/;
    access_log /var/log/nginx/ combined buffer=10k flush=1m;
    error_log /var/log/nginx/ error;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";
    index index.html index.htm index.php;
    charset utf-8;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
    error_page 404 /index.php;
    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php-fpm.socket;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;

Website in minutes

Do you know that you can generate a complete PHP websites in minutes with PHP Website Generator?


  • Free admin dashboard
  • Role based security
  • Login with Facebook, Google and more
  • Queue based email processing
  • Price at $3 for website
  • Uses CodeIgniter framework

Generate website now See Pricing

You can generate an entire website in CodeIgniter using our PHP Website Generator using easy to use wizards. PHP Website Generator provide many features including search with pagination, AJAX based grid data editors, Group based security and free Admin dashboard etc. Please connect with Google or Facebook and to generate your CodeIgniter website in minutes.