Removing index.php from URL in CodeIgniter
Everybody wants to make their URL user friendly,pretty URLs. Why won't any one like pretty URLs? Pretty URLs make the website search engine friendly too besides making the URL easy to understand. While starting with CodeIgniter, we see index.php in the URLs if not removed and this goes against our will. So to get rid of this in CodeIgniter, all we need to do is change the config.php file in application/config/ and add .htaccess to the root directory of CodeIgniter.
Changes to be made in config.php:
1. Change the base url:
$config['base_url'] = 'http://localhost/example/';
2. make the index_page blank
$config['index_page'] = '';
Now the next file to edit is .htacess file, if its not there create on in the root directory. So your directory structure should be like this
->application
->system
->index.php
->license.txt
->README
->.htaccess
The content in .htaccess file should be as follows:
Options -Indexes
Options +FollowSymLinks
Options -MultiViews
DirectoryIndex index.php
<IfModule mod_rewrite.c>
#<IfModule mod_rewrite.so>
RewriteEngine on
RewriteBase /example/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [NC,L,QSA]
RewriteRule ^/?ajax/(.*)$ ajax.php?$1 [NC,QSA,L]
</IfModule>
<IfModule !mod_rewrite.c>
#<IfModule !mod_rewrite.so>
ErrorDocument 404 index.php
</IfModule>
~
While deploying the site to main domain change the RewriteBase /example/ to RewriteBase /.
Comments
Post a Comment