How to Remove index.php from URL in Codeigniter 3
Today, we will explain to you how to remove index.php from URL in Codeigniter 3. in this article, we will give you a simple example of how to remove index.php from url in codeigniter. so you can easily remove the index.php from url.
why need to remove index.php from URL? because when users use it to create SEO friendly, user readability and easy to understand the user.
Now, let’s start to discuss how to remove index.php from the URL in Codeigniter.
Step 1: Updating Config file
in this step, we need to update the below configuration setting in the “application/config/config.php” directory.
1 2 3 4 | //old Code $config['index_page'] = "index.php” //New updated $config['index_page'] = "" |
Step 2: Apache setting
In this step, we need to check “mod_rewrite” is enabled or not. if it’s not enabled then we need to enable “mod_rewrite”. after enabling then restart the apache server. if it’s enabled then we no need to do anything.
why should enable the “mod_rewrite” module because it gives permission for httacess rewrite,
Step 3: Creating .httacess file
In this step, we need to create a .htaccess file on the root directory and paste the below code into this file.
1 2 3 4 | RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] |