Home  >  Article  >  Backend Development  >  How to Remove index.php from URLs in CodeIgniter 2?

How to Remove index.php from URLs in CodeIgniter 2?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-24 08:20:10750browse

How to Remove index.php from URLs in CodeIgniter 2?

Removing index.php from URLs in Codeigniter 2

Many developers have encountered difficulties removing index.php from URLs in Codeigniter 2. While solutions from Codeigniter 1.7 may not be applicable, there are specific steps you can take to achieve this.

Solution:

To remove index.php from URLs in Codeigniter 2, try the following:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /(site)/

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 ^(.*)$ index.php?/ [L]
</IfModule>

Explanation:

This updated code block modifies the RewriteBase directive to include your site folder's name, which is assumed to be "(site)" in this example. By specifying the correct site folder, the server will be directed to the appropriate location to search for the index.php file when requested.

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