Home >Backend Development >PHP Tutorial >How Can I Remove 'index.php' from CodeIgniter URLs Using Apache's Rewrite Capabilities?

How Can I Remove 'index.php' from CodeIgniter URLs Using Apache's Rewrite Capabilities?

DDD
DDDOriginal
2024-12-14 20:42:16153browse

How Can I Remove

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn