Remove index php in codeigniter

Try the following

Open config.php and do following replaces

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

to

$config['index_page'] = ""

In some cases the default setting for uri_protocol does not work properly. Just replace

$config['uri_protocol'] ="AUTO"

by

$config['uri_protocol'] = "REQUEST_URI"

.htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

Note: .htaccess code vary depending on hosting server. In some hosting server (e.g.: Godaddy) need to use an extra ? in the last line of above code. The following line will be replaced with last line in applicable case:

// Replace last .htaccess line with this line
RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 

Remove index php in codeigniter

jjmontes

21.7k4 gold badges35 silver badges50 bronze badges

answered Oct 5, 2013 at 11:06

Rahul TailwalRahul Tailwal

3,1633 gold badges13 silver badges26 bronze badges

8

Step:-1 Open the folder “application/config” and open the file “config.php“. find and replace the below code in config.php file.

//find the below code   
$config['index_page'] = "index.php" 
//replace with the below code
$config['index_page'] = ""

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

Path:
Your_website_folder/
application/
assets/
system/
.htaccess <——— this file
index.php

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 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 below code

//Not needed for CodeIgniter 3 its already there.
//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 does not work because rewrite_module by default disabled so we have need to enable it. for this do the following

  1. Left click WAMP icon
  2. Apache
  3. Apache Modules
  4. Left click rewrite_module

Original Documentation

Example Link

Remove index php in codeigniter

answered Mar 3, 2015 at 10:03

Remove index php in codeigniter

5

Step 1 :

Add this in htaccess file

<IfModule mod_rewrite.c>
  RewriteEngine On
  #RewriteBase /

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [QSA,L]
</IfModule>

Step 2 :

Remove index.php in codeigniter config

$config['base_url'] = ''; 
$config['index_page'] = '';

Step 3 :

Allow overriding htaccess in Apache Configuration (Command)

sudo nano /etc/apache2/apache2.conf

and edit the file & change to

AllowOverride All

for www folder

Step 4 :

Enabled apache mod rewrite (Command)

sudo a2enmod rewrite

Step 5 :

Restart Apache (Command)

sudo /etc/init.d/apache2 restart

answered May 5, 2014 at 7:35

Remove index php in codeigniter

Dino BabuDino Babu

5,7563 gold badges23 silver badges33 bronze badges

7

Step 1 => Place your .htaccess file in root folder where application and system folders exist.

Step 2 => If your web path using sub-folder like - yourdomain.com/project/ - then use following code in htaccess file

RewriteEngine on
RewriteBase    /project/
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /project/index.php/$1 [L]

If your web path using root-folder like - yourdomain.com - then use following code in htaccess file

RewriteEngine on
RewriteBase    /
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

answered Sep 4, 2014 at 9:27

Remove index php in codeigniter

vinodvinod

2,7121 gold badge17 silver badges23 bronze badges

2

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

use

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]

if you have url in this order site.com/index.php/class/method/id

NB:remove index.php in config.php should be config[index_page] = ""

NB: notice the difference at the last line instead of $0 use $1

answered Mar 26, 2014 at 15:10

3

on your htaccess use this,

RewriteEngine On
RewriteBase /root_folder_name/
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Hope this helps.

answered Oct 4, 2013 at 14:08

3

There are two steps:

1) Edit config.php

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

To

$config['index_page'] = '’;

2) Create/Edit .htaccess file

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

Remove index php in codeigniter

Yaseen Ahmad

1,7895 gold badges22 silver badges42 bronze badges

answered Jun 3, 2015 at 6:36

shafishafi

3103 silver badges9 bronze badges

Solved it with 2 steps.

  1. Update 2 parameters in the config file application/config/config.php
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
  1. Update the file .htaccess in the root folder
<IfModule mod_rewrite.c>
    RewriteEngine On
      RewriteBase /
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

answered Feb 28, 2019 at 9:17

Remove index php in codeigniter

1.Create a new file .htaccess on root directory.

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

2. Go to your config.php file and change from $config['index_page'] = 'index.php' to $config['index_page'] = ''

shafi

3103 silver badges9 bronze badges

answered Jun 12, 2015 at 5:47

0

  1. make .htaccess file and put this code

     RewriteEngine on
     RewriteCond $1 !^(index\.php|resources|robots\.txt)
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
    
  2. change

    $config['index_page'] = ''; 
    

remove index.php present in config.php file

  1. rewrite on from your server.

Remove index php in codeigniter

Yaseen Ahmad

1,7895 gold badges22 silver badges42 bronze badges

answered Oct 6, 2016 at 7:53

Remove index php in codeigniter

try this one.It may help you as its working for me.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

put the code in your root htaccess file.and make sure that you have

$config['index_page'] = '';

in your config file.

Please let me know if you face any problem.

answered Oct 5, 2013 at 7:47

Remove index php in codeigniter

ABortyABorty

2,4941 gold badge12 silver badges16 bronze badges

1

+ Copy .htaccess from Application to Root folder
+ edit .htaccess and put

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /ci_test/

    #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]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    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
    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>

Note: make sure your web server is enable for  "rewrite_module"

+ Remove index.php from $config['index_page'] = 'index.php';
- edit config.php in application/config
- search for index.php
change it from  $config['index_page'] = 'index.php'; to  $config['index_page'] = '';

Please watch this videos for reference https://www.youtube.com/watch?v=HFG2nMDn35Q

answered Jul 23, 2015 at 2:09

Well these all answers are good but for a newbie(which is do first time) these are confusing. There are other htaccess files which is reside in controller but we have to edit or add the htaccess in main project folder.

This is your codeigniter folder, where file resides like application,system,assets,uploads etc.

Your_project_folder/
application/
assets/
cgi-bin/
system/
.htaccess---->(Edit this file if not exist than create it)
index.php

Change this file as written below:

<IfModule mod_rewrite.c>
  RewriteEngine On
  # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
  #  slashes.
  # If your page resides at http://www.example.com/mypage/test1
  # then use RewriteBase /mypage/test1/
  # Otherwise /
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  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: Anand Pandey
  ErrorDocument 404 /index.php
</IfModule>

and yes of course you need to change two lines of code in the application/config/config.php

//find the below code   
$config['index_page'] = "index.php";
$config['uri_protocol'] ="AUTO" 
//replace with the below code
$config['index_page'] = "";
$config['uri_protocol'] = "REQUEST_URI";

answered Nov 13, 2017 at 5:55

Remove index php in codeigniter

Anand PandeyAnand Pandey

2,0253 gold badges19 silver badges37 bronze badges

1

you can go to config\config.php file and remove index.php value from this variable

$config['index_page'] = 'index.php'; // delete index.php

create .htaccess file and paste this code in it.

<IfModule mod_rewrite.c>

 Options +FollowSymLinks

 RewriteEngine On
 #Send request via index.php
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

good chance

Remove index php in codeigniter

answered Apr 11, 2014 at 21:16

Remove index php in codeigniter

Both development and production

    # Development
    RewriteEngine On
    RewriteBase /your_local_folder/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|images|scripts|styles|vendor|robots\.txt)
    RewriteRule ^(.*)$ index.php/$1 [L]

    #Production PHP5 CGI mode
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|images|scripts|styles|vendor|robots\.txt)
    RewriteRule ^(.*)$ index.php?/$1 [L]

answered Aug 6, 2014 at 4:55

first of all you have to on the apache server rewrite engine on.this link will help you for that

http://www.anmsaiful.net/blog/php/enable-apache-rewrite-module.html

RewriteEngine On
RewriteBase /your_folder_name/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?/$1 [L]

this will be your .htaccess file. now try it .this setting works for me.

answered Jan 15, 2015 at 5:56

Remove index php in codeigniter

  Removing index.php from url of codeigniter   

Three steps are require to remove index.php from url in Codeigniter.

1)Create .htacess file in parallel to application holder and just copy past the following code:

RewriteEngine On
RewriteBase /CodeIgniter/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

2) Change $config['index_page'] to blank in config.php in application folder as below:

$config['index_page'] = '';

3) Enable “rewrite_module” of apache.

answered Jun 3, 2014 at 13:17

Add .htaccess on your root folder and past the following code:

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

answered Jul 28, 2021 at 8:39

Remove index php in codeigniter

Abd AbughazalehAbd Abughazaleh

3,4952 gold badges33 silver badges43 bronze badges

Only three steps are require to remove index.php from url in Codeigniter

1) Create .htacess file in parallel to application holder and just copy past the following code:

RewriteEngine On
RewriteBase /CodeIgniter/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

2) Change $config['index_page'] to blank in config.php in application folder as below:

$config['index_page'] = '';

3) Enable “rewrite_module” of apache.

Restart your apache and its done.

Details : http://sforsuresh.in/removing-index-php-from-url-of-codeigniter-in-wamp/

answered May 16, 2014 at 14:05

Remove index php in codeigniter

Suresh KamrushiSuresh Kamrushi

14.9k12 gold badges75 silver badges87 bronze badges

I think your all setting is good but you doing to misplace your htaccess file go and add your htaccess to your project file

project_folder->htaccess

and add this code to your htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

answered May 30, 2016 at 5:57

Remove index php in codeigniter

Yaseen AhmadYaseen Ahmad

1,7895 gold badges22 silver badges42 bronze badges

you can go to application\config\config.php file and remove index.php

 $config['index_page'] = 'index.php';   // delete index.php

Change to

 $config['index_page'] = '';

answered Aug 10, 2017 at 17:25

Remove index php in codeigniter

try this RewriteEngine On

        # Removes index.php from ExpressionEngine URLs
        RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

answered Apr 24, 2019 at 10:56

Remove index php in codeigniter

KashifKashif

1,10814 silver badges18 bronze badges

This works for me. Tested in codeigniter 3.1.11, PHP 5.6.40 I use a virtualhost in my apache2 config in testing server.

<VirtualHost *:80>
     ServerAdmin 
     DocumentRoot (__DIR__)
     ServerName mydomain
     ##ErrorLog "logs/dummy-host2.example.com-error.log"
     ##CustomLog "logs/dummy-host2.example.com-access.log" common
     <Directory "(__DIR__)">
        Require all granted
        AllowOverride All
   </Directory>
</VirtualHost>

And /.htaccess content

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

answered Jun 26, 2020 at 11:51

Remove index php in codeigniter

You can remove index.php from url by placing some code in .htaccess

File path: root > .htacess

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Hope it will works.

Remove index php in codeigniter

answered Oct 23, 2018 at 8:27

Remove index php in codeigniter

Rokan NashpRokan Nashp

3314 silver badges13 bronze badges

Follow these step your problem will be solved

1- Download .htaccess file from here https://www.dropbox.com/s/tupcu1ctkb8pmmd/.htaccess?dl=0

2- Change the CodeIgnitor directory name on Line #5. like my directory name is abc (add your name)

3- Save .htaccess file on main directory (abc) of your codeignitor folder

4- Change uri_protocol from AUTO to PATH_INFO in Config.php file

Note: First of all you have to enable mod_rewrite from httpd.conf of apachi by removing the comments

answered Aug 28, 2014 at 12:04

0

Use this code. Change the 2nd line as you have your folder name. Where index.php file and folders application, system folder lie. Mostly problems happen due to second line. we don't configure the folder name where project is place. Important is 2nd line. This is simple to remove the index.php. RewriteEngine on RewriteBase /project_folder_name RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php/$0 [PT,L]

#RewriteEngine on
#RewriteCond $1 !^(index\.php|images|robots\.txt)
#RewriteRule ^(.*)$ index.php/$1 [L]    

Go to controller/config.php file.

config['index_url']='';

Reference for more study.

https://ellislab.com/expressionengine/user-guide/urls/remove_index.php.html

https://ellislab.com/blog/entry/fully-removing-index.php-from-urls

answered Dec 18, 2014 at 4:49

Remove index php in codeigniter

Besides these answers, one can just, add index.php or edit it (if it is already there) - for security you want to disable index.php anyway, from listing the files in your website directory - then change the content into

<?php
   header('location:your_required_starting.php'); 
?>

answered Nov 24, 2016 at 7:21

Minor thing: (Optional)

Try restarting your Apache after updating the rewrite engine status in vhosts as Rewrite ON.

One critical thing to notice:

In Apache vhosts file, check whether you have this script line AllowOverride None If yes, please remove/comment this line.

My vhosts file script: (Before)

<VirtualHost *:80>
    DocumentRoot "/path/to/workspace"
    ServerName ciproject
    ErrorLog "/path/to/workspace/error.log"
    CustomLog "/path/to/workspace/access.log" common
    Directory   "/path/to/workspace">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory> 
</VirtualHost>

My vhosts file script: (After)

<VirtualHost *:80>
    DocumentRoot "/path/to/workspace"
    ServerName ciproject
    ErrorLog "/path/to/workspace/error.log"
    CustomLog "/path/to/workspace/access.log" common
    Directory   "/path/to/workspace">
        Options Indexes FollowSymLinks
        #AllowOverride None
        Order allow,deny
        Allow from all
    </Directory> 
</VirtualHost>

I faced the same problem, struggled for around 1 day, all were fine. Later, by trial and error method, found this thing. After removing this, my job was accomplished. The URL now does not look up for index.php :)

Remove index php in codeigniter

Yaseen Ahmad

1,7895 gold badges22 silver badges42 bronze badges

answered Sep 5, 2017 at 13:26

if all the above solution not work then in your project folder their will be two files index.html and index.php, rename index.html to index_1.html and browse your project.

answered Mar 15, 2018 at 15:28

Remove index php in codeigniter

Mohsin ShoukatMohsin Shoukat

1,1421 gold badge13 silver badges21 bronze badges

Note the difference with the added "?" character after ".php", especially when dealing with CodeIgniter:

RewriteRule ^(.*)$ index.php/$1 [L]

vs.

RewriteRule ^(.*)$ index.php?/$1 [L]

It depends on several other things.. if doesn't work, try the other option!

answered Aug 10, 2018 at 5:28

Remove index php in codeigniter

eyal_katzeyal_katz

1,02310 silver badges17 bronze badges

How do I delete an index in CI?

How to remove index..
Create a .htaccess file. Firstly we will need to create a . ... .
Removing index.php file. Open the config. ... .
Enable apache mode rewrite. Now, we will need to activate the mod_rewrite with the help of the following command. ... .
Restart Apache..

What is .htaccess file in CodeIgniter?

htaccess file in CodeIgniter. 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.

Where is .htaccess file located in CodeIgniter?

You should place your . htaccess file at your root directory not Inside the application folder. Show activity on this post. Go to application/config/config.

How do I delete a public in ci4?

How to remove public/index..
Step 1: Change in App.php File. The first step is to open the app. app file. ... .
Step 2: Copy index.php and .htaccess. Visit inside public directory. And copy index. ... .
Step 3: Change In index. php..