How to remove index.php from codeigniter path?

Member

by addison , in category: PHP Frameworks , 8 months ago

How to remove index.php from codeigniter path?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by larissa , 8 months ago

@addison 

To remove index.php from the URL in CodeIgniter, you need to configure your web server and update the .htaccess file.

  1. Update config.php: In your CodeIgniter application directory, open the config.php file located at application/config/config.php. Search for the following line:
1
$config['index_page'] = 'index.php';


Change it to:

1
$config['index_page'] = '';


  1. Create or Update .htaccess file: Create a .htaccess file in the root directory of your CodeIgniter application (where index.php is located) if it doesn't already exist. If it already exists, update it with the following code:
1
2
3
4
5
6
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>


This code will remove index.php from the URL and redirect all requests to index.php.

  1. Update Virtual Host Configuration (if needed): If you are using Apache web server, make sure that the AllowOverride directive is set to All in your Apache configuration file or virtual host configuration. This allows .htaccess files to override server configuration settings.


For example, in your Apache configuration file or virtual host configuration, you should have something like this:

1
2
3
4
5
<Directory /var/www/html>
  Options Indexes FollowSymLinks
  AllowOverride All
  Require all granted
</Directory>


Restart your web server after making these changes, and you should now be able to access your CodeIgniter application without index.php in the URL.