Clean URLs in CodeIgniter: How to Remove "index.php" from Paths
In CodeIgniter, the "index.php" segment in URLs can be unsightly. To achieve clean, non-index.php-fied URLs, you can leverage Apache's rewrite capabilities.
Apache Rewrite Using .htaccess
Place a .htaccess file in your application's root web directory and add the following content:
RewriteEngine on RewriteCond !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt) RewriteRule ^(.*)$ /index.php/ [L]
This rule ensures that requests not targeting specific files (such as JavaScript, CSS, images, or robots.txt) are redirected to index.php with the original URI appended.
Improved Rewrite Version
An alternative rewrite version that handles URL parameters and special characters can be found here:
http://snipplr.com/view/5966/codeigniter-htaccess/
The above is the detailed content of How Can I Remove 'index.php' from CodeIgniter URLs Using Apache's Rewrite Capabilities?. For more information, please follow other related articles on the PHP Chinese website!