This tutorial will  focus on how to remove index.php in CodeIgniter URLs using Htaccess to make your website URLs appealing to users and search engines.

What is CodeIgniter?

CodeIgniter is a PHP framework used for building websites and web systems.

Developers use frameworks, such as CodeIgniter, to speed up their development time and to access common PHP code. Rather than reinventing the wheel and creating code that has been used many times before, CodeIgniter provides quick access to popular code.

Another reason developers love CodeIgniter is because if it’s small package size. Unlikely other PHP frameworks such as laravel, CodeIgniter is small in size yet very scale-able. Therefore, developers sometimes favour CodeIgniter for a quick deployment and scale-able projects.

CodeIgniter appends index.php to its URLs, leaving an unpretty sight in the address bar of your visitors.

By learning how to remove index.php from CodeIgniter using Htaccess, you can improve your SEO and make your website URLs more appealing to visitors.

Removing index.php in CodeIgniter using Htaccess

Difficulty: Beginner

Tutorial Time: 5 Minutes


How to remove index.php in CodeIgniter using Htaccess

To begin with, you should have a website and domain configured with the CodeIgniter files uploaded.

Firstly, create a file in the root of your CodeIgniter directory called .htaccess

Secondly, add the following code into the htaccess file:

RewriteEngine On
RewriteBase /
# Send /index.php/ to /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

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


No more unfriendly URLs!

Apache will now detect traffic visiting your website and send any requests from /index.php/ to the root folder of your website.

To sum up, your website now has user friendly slugs which are easy to read and easy to crawl for search engines. If you enjoyed this article, be sure to check our more of our CodeIgniter content.