How to remove index.php from URL in CodeIgniter

Send Email Codeigniter Login Registration Join Query CodeIgniter Interview Questions

Now i am going to share with you How to remove index .php from URL in CodeIgniter using .htaccess. htaccess is the shortened used for Hypertext Access, which is a powerful configuration file that controls the directory “.htaccess”. It is used by Apache based web servers to control various server features.

Here is Step for remove index.php from URL in CodeIgniter using .htaccess

Using HTACCESS

  1. First Go to your site folder and Open Htaccess File
  2. Then after add Below code in Htacces File
    RewriteEngine on
    RewriteCond $1 !^(index\.php|public|\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?$1
  3. Then Update <Directory /var/www/> Section in  /etc/apache2/apache2.conf
  4. Here is The Code For apache2.conf

    Options Indexes FollowSymLinks
    AllowOverride all
    Require all granted

See Second Method

Step:-1  Open the file config.php located in application/config path.  Find and Replace the below code in config.php  file.

//  Find the below code

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

//  Remove index.php

$config['index_page'] = ""

Step:-2  Go to your CodeIgniter folder and create .htaccess  file.

Path:
Your_website_folder/
application/
assets/
system/
user_guide/
.htaccess <--------- this file
index.php
license.txt

Step:-3  Write below code in .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Step:-4  In some cases the default setting for uri_protocol does not work properly. To solve this issue just open the file config.php located in application/config and then find and replace the code as:

//  Find the below code

$config['uri_protocol'] = "AUTO"

//  Replace it as

$config['uri_protocol'] = "REQUEST_URI" 

Also Read: Codeigniter Interview Question answes

If you have any Question Then add your Question in comment and Fill Free to Ask Question Or Contact us

One thought on “How to remove index.php from URL in CodeIgniter

Leave a Reply