Removing index.php from URL and setup config.php

config.php is located at application/config folder.

Note :all the line number may not be accurate.

At line 26 there is a setup $config[‘base_url’] = '';
Here we should set our project url.
This setup is used for producing actual links.
As our current project url is http://localhost/ci/ so the setup should be like this.

$config['base_url'] = 'http://localhost/ci';

Remove Index.php

  • at config.php line 38 set the config like this //$config['index_page'] = 'index.php';//replace this line with bellow line
    $config['index_page'] = '';
  • at root(ci) folder create a .htaccess  file and include follwing codes[if your server is linux or supports .htaccess]
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
  • For IIS you can look here

There are nice comments before all config explaining what it does.
But I am explaining some config whose are needed most of the time.

  • $config['allow_get_array'] = TRUE/FALSE;//if you want to enable GET method.
  • $config['sess_driver'] = 'database';//To manage session with database.
    $config['sess_save_path'] = 'your_table_name';//To manage session with database.
    //For more details go to How I can set a session in codeigniter 3 database?
  •  
Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *