Removing ‘index.php’ from CodeIgniter URL

CodeIgniter is the one of most famous PHP Framework now. But if we’re using CodeIgniter, by default the URL will be shown as http://localhost/index.php/welcome. Some people doesn’t like this way to accessing a website, the index.php suffix in the URL.

Here is some step that can make us accessing the website using http://localhost/welcome. But we’re also still accessing the url ith index.php suffix. Before, i will list my system so if we’re using different system it may cause different solution.

  1. Apache 2.2.14
  2. PHP 5.2.12

STEP one : create .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#‘system’ can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn’t true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
#Submitted by Michael Radlmaier (mradlmaier)
RewriteCond $1 !^(index.php|images|robots.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
# If we don’t have mod_rewrite installed, all 404’s
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php
</IfModule>

STEP two : edit CodeIgniter Configuration

$config['index_page'] = "index.php";

TO

$config['index_page'] = "";

That’s all. Go and try that….

Source and References

  1. http://arifn.web.id/blog/2009/02/06/codeigniter-removing-indexphp.html

Leave a Reply

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

Post Navigation