Home  >  Article  >  Backend Development  >  How to Remove \'index.php\' from CodeIgniter 2.0 URLs?

How to Remove \'index.php\' from CodeIgniter 2.0 URLs?

DDD
DDDOriginal
2024-11-19 09:23:03254browse

How to Remove

Removing "index.php" from URLs in CodeIgniter 2.0

Issue:

Many users encounter difficulties removing the "index.php" segment from their CodeIgniter 2 URLs. Previous solutions used in CodeIgniter 1.7 no longer suffice.

Troubleshooting Steps:

1. Rewrite Rules:

  • As per the user's query, various .htaccess codes have been attempted without success. Notably, the first code snippet provided includes "RewriteBase /", which may be contributing to the problem. Remove "/index.php" from Rewrite Rules: Modify the .htaccess code as follows:
RewriteEngine On
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]

2. URI Protocol and Index Page:

  • Ensure that $config['uri_protocol'] is set to REQUEST_URI in your config.php file.
  • Set $config['index_page'] to an empty string ("") as you've already done.

3. File Structure:

  • Verify that your file structure is correct, as specified by the user: 192.168.0.130/(site)/.
  • Ensure that the default folders are: application, CI-2.0, and index.php.

4. .htaccess Optimization:

  • Try the following optimized .htaccess code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/(site)/ [L]
  • Replace "/(site)/" with the actual name of your site folder.

5. Change Path Separator:

  • In some cases, changing the path separator from "/" to "" may resolve the issue.

6. Contact Support:

  • If none of the above solutions work, consider reaching out to CodeIgniter's official support channels.

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