Skip to content Skip to sidebar Skip to footer

Codeigniter remove index.php from url

Reading Time: < 1 minute

When we are working with codeigniter you can see index.php in the url after the base_url.So here we’re discuss how to remove index.php part from the url.We can do it using htaccess file and config file.

Here is the example.
http://www.example.com/index.php/about-us
We want to remove index.php part from this url as follows.
http://www.example.com/about-us

remove index.php from url using htaccess and config file?

1-Go to the /application/config directory and open the config.php file.
2-Put the “index.php” variable as empty.

$config['index_page'] = ""; // default value is "index.php"

3-Put the “uri_protocol” as “REQUEST_URI”.

$config['uri_protocol'] = "REQUEST_URI" // default value is "AUTO"

4-Go to the root codeIgniter directory(same location of “system” folder) and open the htaccess file. If not exist create a new one.
Codeigniter remove index.php from url
Copy the following code and paste and save it.

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

If not success, put this code instead of the above code.

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

Note: If you call with index.php part, no problems, it is also work!
If you got “Internal server Error!” Please double check your .htaccess file and config.php file.
That’s only.