Remove index.php in CodeIgniter url and default controller

Remove index.php in CodeIgniter url and default controller:

Few people are asked me how to “Remove index.php in CodeIgniter url and default controller in CodeIgniter”.

CodeIgniter   EllisLab

CodeIgniter(CI) is good application to build web portals using PHP MVC frame works and learning PHP MVC also for beginners, Okay Lets move our topic to “Remove index.php in CodeIgniter(CI) url and default controller”.

Follow the steps for removes “index.php” in URL

Step 1: Download the CI from CI official web site, Click here for CI download

Step 2: If you want rename your download CI yes you can as you want or leave as it is.Then place the application folder into your local server root. Suppose if your using           WAMP Server the root will be Local drive:\\wamp\www\your CI application.Suppose if your using XAMPP the root will be Local drive:\\xampp\\htdocs\your CI application.

Step 3: Now you have to enable “rewrite_module” in our local servers for WAMP, Click on    quick lunch icon of WAMP >> Apache >> Apache modules >> rewrite_module, enable the “rewrite_module” and restart WAMP Server. For XAMPP, XAMPP >> apache >> conf >> open httpd.conf file and find “LoadModule rewrite_module modules/” make sure this line comment or not if yes just remove “#” at starting of the line and restart XAMPP.

Step 4: Go to your server root directory and open “CodeIgniter application” folder then find “application” folder and open it and find “config” folder and open it then find “config.php” file and open using PHP program file editor. for example I was renamed the CI application file like “codeigniter213” so my codeigniter application flow like as below “codeigniter >> application >> config >> config.php”.

Step 5: Find these variables in “config.php” and change like as shown below.                      $config[‘base_url’] = ”;  and replace with your site URL like this “$config[‘base_url’] = ‘ http://localhost:85/CodeIgniter213/ ‘; ” and ” $config[‘index_page’] = ‘index.php’; ” make this variable as empty like ” $config[‘index_page’] = ”; ” Note: Here “CodeIgniter213” is consider for example purpose only you have to change as you need.

Step 6: Create a file name ” .htaccess ” and place this file into CodeIgniter application folder, For example “codeigniter213 >> .htaccess “, Open file any text editor copy and paste the flowing code in ” .htaccess

<IfModule mod_rewrite.c> 
 RewriteEngine On
 #rename "codeIgniter213" with your application directory 
 #For example you rename the entire CodeIgniter application as "mysite" 
 #then, the "RewriteBase /" will be like this "RewriteBase /mysite" 
 #same as at line number 10, "RewriteRule ^(.*)$ /codeIgniter213/index.php #/$1 [L]" will be like this "RewriteRule ^(.*)$ /mysite/index.php/$1 [L]"
 RewriteBase /codeIgniter213
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ /codeIgniter213/index.php/$1 [L]

If your confuses with above code you can download ” .htaccess ” file, Click here. Note : you have to replace “codeigniter213” with CI application name. That’s it your done.

Follow the steps to change default controller of your CI application

What is default controller ? Ans: When we try to enter our CodeIgniter application URL in bower at that time CodeIgniter check which controller it has to call as configure in “routes.php” file with “default_controller“.

Open “routes.php” file which is located in “config folder of application folder” in CodeIgniter application for example “codeigniter213 >> application >> config >> routes.php “. Find the ” $route[‘default_controller’] = “welcome”; ” here welcome is default controller for CodeIgniter to default you have to create a new controller based on CodeIgniter controller creation rules for more how to controllers in CodeIgniter Click here .

Suppose we create a new controller called “test” and i want make this as my default controller, Just i need to change  ” $route[‘default_controller’] = “welcome”; ” this veriable as ” $route[‘default_controller’] = “test“; ” in “routes.php” file.

Please don't hesitate to contact me on this.
You can comment your opinion ,Thank you, 
Achyuth 401

5 thoughts on “Remove index.php in CodeIgniter url and default controller

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s