Home >Backend Development >PHP Tutorial >How Can I Remove index.php from URLs in CodeIgniter 2 Using .htaccess?

How Can I Remove index.php from URLs in CodeIgniter 2 Using .htaccess?

Linda Hamilton
Linda HamiltonOriginal
2024-11-18 09:03:02732browse

How Can I Remove index.php from URLs in CodeIgniter 2 Using .htaccess?

Remove index.php from URL in CodeIgniter 2

In CodeIgniter 2, removing the index.php from URLs requires a specific .htaccess configuration. However, some users have encountered issues when adapting .htaccess code from CodeIgniter 1.7 to 2.

Troubleshooting .htaccess Configuration

To resolve this problem, consider trying the following .htaccess code:

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

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /(site)/index.php?/ [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /(site)/index.php?/ [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /(site)/index.php?/ [L]
</IfModule>

Replace "(site)" with the actual name of your site folder.

Additional Adjustments

In your index.php file, ensure that the following settings are configured correctly:

  • $config['uri_protocol'] = 'REQUEST_URI';
  • $config['index_page'] = '';

Updated Folder Structure

Note that if you have modified the default folder structure, adjust the paths accordingly:

  • application
  • CI-2.0 (or whatever you renamed the Core folder to)
  • index.php

To ensure proper functionality, make sure the paths in index.php accurately reflect these changes.

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