Home >Backend Development >PHP Tutorial >How to Remove index.php from CodeIgniter URLs Using .htaccess?

How to Remove index.php from CodeIgniter URLs Using .htaccess?

Barbara Streisand
Barbara StreisandOriginal
2024-12-31 09:48:15920browse

How to Remove index.php from CodeIgniter URLs Using .htaccess?

Removing index.php from CodeIgniter URLs Using Rewrite Rules

To remove index.php from CodeIgniter URLs, you can utilize the mod_rewrite module with Apache2. Here's how to do it:

1. Configure Config.php

Open config.php and change the following line:

$config['index_page'] = "index.php";

to:

$config['index_page'] = "";

2. Set URI Protocol

If the default AUTO setting for uri_protocol in config.php is not working, replace it with:

$config['uri_protocol'] = "REQUEST_URI";

3. Modify .htaccess File

Add the following code to your root .htaccess file:

RewriteEngine on
RewriteCond  !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L,QSA] 

Note: The specific .htaccess code may vary slightly depending on your hosting server. Some servers require an additional '?' at the end of the last line:

RewriteRule ^(.*)$ index.php?/ [L,QSA] 

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