CodeIgniter URL Rewrite for Nginx Server CodeIgniter URL Rewrite for Nginx Server codeigniter codeigniter

CodeIgniter URL Rewrite for Nginx Server


index() is called by default , but if you want to do it for other functions , you can make use of URI Routing feature in CI.

Add this to routes.php in config directory.

$route['view/(:num)'] = "view/index/$1";


Remove the trailing index from all controllers using the following configuration in Nginx

# removes trailing "index" from all controllersif ($request_uri ~* index/?$){    rewrite ^/(.*)/index/?$ /$1 permanent;}

Explicitly you can route the URLs from CodeIgniter Routing file located in

./application/config/routes.php

Insert this code. This should work for both Nginx or Apache Servers.

// hide index from all controllers$route['(:any)/(:any)'] = "$1/index/$2";// hide only from View Controller$route['view/(:any)'] = "view/index/$1";// hide only from View with numeric parameter$route['view/(:num)'] = "view/index/$1";

Find more information about Nginx URL Rewrite from documentation. Hope this helps you. Thanks!!