The default url of codeigniter is look like this [sitename]/index.php/[rest of the slug], and this is called not pretty url, so how to remove index.php from URL on CodeIgniter? Follow this steps to solve that.
Step: -1 Open the folder “application/config” and open the file “config.php”, find and replace the bellow code in config.php file
1 2 3 4 |
//find the below code $config['index.php'] = "index.php"; //replace with the below code config['index.php'] = ""; |
Step: -2 Go to your CodeIgniter folder and create .htaccess
1 2 3 4 5 6 7 |
Path: Your_website_folder/ application/ assets/ system/ .htaccess <------ this file index.php |
Step: -3 Write below code in .htaccess file
1 2 3 4 5 6 |
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] </IfModule> |
Step: -4 In some case the default setting for uri_protocol does not work properly. To solve this problem just open the file “application/config/config.php”, then find and replace the bellow code
1 2 3 4 |
//find the below code $config['uri_protocol'] = "AUTO" //replace with the below code $config['uri_protocol'] = "REQUEST_URI" |
Thats all but in wamp server it doest not work because rewrite_module by default disabled so we have need to enable it. For this do the following
1 2 3 4 |
1) Left click WAMP icon 2) Apache 3) Apache Modules 4) Left click rewrite_module |