How to remove index.php from url in codeigniter?

Member

by denis , in category: PHP Frameworks , a month ago

How to remove index.php from url in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by edmond_brakus , a month ago

@denis 

To remove index.php from the URL in CodeIgniter, you need to make sure that mod_rewrite is enabled in your Apache configuration and that you have an .htaccess file in your CodeIgniter root directory.

  1. Enable mod_rewrite in Apache: Open the Apache configuration file (usually located at /etc/httpd/httpd.conf or /etc/apache2/apache2.conf). Search for the line LoadModule rewrite_module modules/mod_rewrite.so and make sure it is not commented out (remove the # if it is). Save the configuration file and restart Apache.
  2. Create an .htaccess file in your CodeIgniter root directory: Create a new file named .htaccess in your CodeIgniter root directory if it doesn't already exist. Add the following code to the .htaccess file:
1
2
3
4
5
6
7
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>


  1. Configure your CodeIgniter config.php file: Open the config.php file located in application/config/ directory of your CodeIgniter installation. Find the following line: $config['index_page'] = 'index.php'; and change it to $config['index_page'] = '';


With these steps, index.php should be removed from the URL in your CodeIgniter application. Make sure to test your application thoroughly to ensure that everything is working correctly.