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
Release: 2024-12-14 20:42:16
Original
152 people have browsed it

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]
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template