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
Release: 2024-12-31 09:48:15
Original
936 people have browsed it

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";
Copy after login

to:

$config['index_page'] = "";
Copy after login

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";
Copy after login

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

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

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!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template