how to remove index.php in codeigniter
- Open the
config.php
file located in theapplication/config
directory. Find the
$config['index_page']
variable and set its value to an empty string:php $config['index_page'] = '';
Open the
.htaccess
file in the root directory of your CodeIgniter project. If it doesn't exist, create one.Add the following code to remove
index.php
from the URLs:htaccess <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] </IfModule>
Ensure that the
mod_rewrite
module is enabled in your Apache server. You can do this by uncommenting the following line in the Apache configuration file (httpd.conf
):apache LoadModule rewrite_module modules/mod_rewrite.so
In some cases, you might need to set the
AllowOverride
directive toAll
for the directory where your CodeIgniter application is located. Locate your virtual host configuration file or add the following within aDirectory
block:apache <Directory "/path/to/your/codeigniter"> AllowOverride All </Directory>
Restart your Apache server for the changes to take effect.
If you are using NGINX instead of Apache, you can use the following configuration in your NGINX server block:
nginx location / { try_files $uri $uri/ /index.php?$query_string; }
Restart your NGINX server for the changes to take effect.
Note: Replace "/path/to/your/codeigniter"
with the actual path to your CodeIgniter installation directory.