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.
server{ server_name thephpcode.com; root /opt/www/$server_name/; access_log /var/log/nginx/thephpcode.com.log combined buffer=10k flush=1m; error_log /var/log/nginx/thephpcode.com.error.log 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; } }
Do you know that you can generate a complete PHP websites in minutes with PHP Website Generator?