How to remove index.php from CodeIgniter URL like a PRO

Besarion Turmanauli
1 min readFeb 15, 2019

--

First step when creating a web application or website using CodeIgniter framework is probably to remove the index.php from all of its URLs, we can’t just load an URL without index.php because browser will show the 404 (page not found) error.

Why is index.php displayed in the URL by default

In CodeIgniter, all controllers and views are loaded from index.php file and this makes the model/view/controller (MVC) structure work. CodeIgniter framework translates strings after each forward slash into a controller name, method and arguments.

Steps to remove index.php the right way

  1. Go to your CodeIgniter directory / application / config / config.php and change index_page parameter so that it looks exactly like this:
$config['index_page'] = '';

2. Create .htaccess file in your CodeIgniter directory and add the following content:

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

3. Now load your URL without index.php in it (use hard refresh Ctrl+F5) if necessary.

Want more?

Go to this link and register to get $100 in cloud credits from DigitalOcean today and deploy your app in seconds.

Check this medium article to know why it’s in your interests to use DigitaOcean’s cloud hosting as a web developer.

--

--

Responses (1)