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

Linda Hamilton
Release: 2024-11-18 09:03:02
Original
658 people have browsed it

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

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!

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