Home > Backend Development > PHP Tutorial > How Can I Remove 'index.php' from CodeIgniter URLs Despite Having mod_rewrite Enabled?

How Can I Remove 'index.php' from CodeIgniter URLs Despite Having mod_rewrite Enabled?

Mary-Kate Olsen
Release: 2024-12-24 03:56:19
Original
563 people have browsed it

How Can I Remove

Configuring CodeIgniter to Remove "index.php" from URLs

Your current issue revolves around removing "index.php" from your URLs in CodeIgniter. Despite having mod_rewrite enabled in Apache2 and setting '$config['index_page'] = '';' in the configuration file, you're still not able to achieve the desired outcome.

Let's troubleshoot the issue and explore the necessary modifications:

1. Verify Configuration Settings:

Ensure that the following changes have been made in config.php:

  • Replace $config['index_page'] = "index.php" with $config['index_page'] = ""

2. Optimize .htaccess File:

In your root .htaccess file, employ the following code:

RewriteEngine on
RewriteCond  !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L,QSA]
Copy after login

Additional Considerations:

  • In some hosting environments (e.g., Godaddy), you may need to add an extra '?' character to the last line of the .htaccess code:
RewriteRule ^(.*)$ index.php?/ [L,QSA]
Copy after login
  • If the default setting for $config['uri_protocol'] is not functioning properly, try replacing it with $config['uri_protocol'] = "REQUEST_URI".

Tips:

  • Clear your browser cache after making these modifications to ensure the changes take effect.
  • If you encounter any further difficulties, consult the official CodeIgniter documentation or seek assistance from the community forums.

The above is the detailed content of How Can I Remove 'index.php' from CodeIgniter URLs Despite Having mod_rewrite Enabled?. 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