Home >Backend Development >PHP Tutorial >How Can I Remove 'index.php' from CodeIgniter URLs?

How Can I Remove 'index.php' from CodeIgniter URLs?

Barbara Streisand
Barbara StreisandOriginal
2024-12-24 17:23:17934browse

How Can I Remove

Removing "index.php" from CodeIgniter URLs

In CodeIgniter, by default, URLs include the "index.php" segment, leading to less appealing and verbose URLs. This can be easily rectified to achieve a more streamlined and intuitive user experience.

Apache Configuration with .htaccess

For Apache web servers, create a ".htaccess" file within the root web directory and include the following code:

RewriteEngine on
RewriteCond  !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/ [L]

This code instructs the server to rewrite URLs that do not match specific exceptions, such as "index.php" or static files (e.g., JavaScript, CSS, images), and redirect them through the "index.php" file with the matching segment appended.

Alternative Approach

An alternative configuration approach is provided in the following URL:

[CodeIgniter .htaccess Configuration](http://snipplr.com/view/5966/codeigniter-htaccess/)

The above is the detailed content of How Can I Remove 'index.php' from CodeIgniter URLs?. 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