Home > Backend Development > PHP Tutorial > How can I remove index.php from URLs in CodeIgniter 2?

How can I remove index.php from URLs in CodeIgniter 2?

Patricia Arquette
Release: 2024-11-19 07:08:02
Original
858 people have browsed it

How can I remove index.php from URLs in CodeIgniter 2?

Removing index.php from URLs in Codeigniter 2

In Codeigniter 2, removing index.php from URLs can be achieved by modifying the .htaccess file. Here's how:

  1. Open the .htaccess file located in the root directory of your Codeigniter application.
  2. Add the following code to the file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
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 ^(.*)$ /(site)/index.php?/ [L]
</IfModule>
Copy after login

Ensure you replace "(site)" with the actual name of your site folder. This ensures that the rewrite rules look for the index.php file within the correct folder structure.

  1. Make sure $config['uri_protocol'] is set to either REQUEST_URI or PATH_INFO in your config.php file.
  2. Set $config['index_page'] to an empty string ("") in your config.php file.

Additional Notes:

  • If the above doesn't work, try adding an additional RewriteRule to the .htaccess file:

    RewriteRule ^(.*)$ - [E=BASE:www\.mysite\.com]
    Copy after login
  • You may need to adjust the RewriteBase directive if your site is not located in the root directory of your server.
  • Ensure that the mod_rewrite module is enabled on your server.

The above is the detailed content of How can I remove index.php from URLs in CodeIgniter 2?. For more information, please follow other related articles on the PHP Chinese website!

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