Home > Article > Backend Development > How can I remove index.php from URLs in CodeIgniter 2?
Removing index.php from URLs in Codeigniter 2
In Codeigniter 2, removing index.php from URLs can be achieved by modifying the .htaccess file. Here's how:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} ^system.* RewriteRule ^(.*)$ /index.php?/ [L] RewriteCond %{REQUEST_URI} ^application.* RewriteRule ^(.*)$ /index.php?/ [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /(site)/index.php?/ [L] </IfModule>
Ensure you replace "(site)" with the actual name of your site folder. This ensures that the rewrite rules look for the index.php file within the correct folder structure.
Additional Notes:
If the above doesn't work, try adding an additional RewriteRule to the .htaccess file:
RewriteRule ^(.*)$ - [E=BASE:www\.mysite\.com]
The above is the detailed content of How can I remove index.php from URLs in CodeIgniter 2?. For more information, please follow other related articles on the PHP Chinese website!