Home  >  Article  >  Backend Development  >  How to Remove "index.php" from CodeIgniter URLs?

How to Remove "index.php" from CodeIgniter URLs?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-12 18:50:02996browse

How to Remove

CodeIgniter .htaccess and URL Rewriting Issues

Navigating CodeIgniter applications often requires removing "index.php" from the URL, allowing users to access pages with a cleaner syntax. However, new users may encounter difficulties with this process.

The key to removing "index.php" lies in modifying the application config file (application/config.php) and creating a .htaccess file in the root directory.

1. Application Configuration:

In application/config.php, ensure the following settings:

$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

2. .htaccess File:

Create a .htaccess file in the root directory with the following code:

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

3. Rewrite Engine Enablement:

Ensure the rewrite engine is enabled by:

  • Initiating it with "a2enmod rewrite".
  • Changing "AllowOverride None" to "AllowOverride All" in /etc/apache2/sites-enabled/000-default or /etc/apache2/apache2.conf.
  • Restarting the server with the command "sudo /etc/init.d/apache2 restart".

Additional Notes:

If accessing a page via "localhost/ci/about" fails, consider:

  • Using "localhost/ci/index.php/about" or creating an "about" directory in application/.
  • Checking for any directives in the .htaccess file that may be interfering.

The above is the detailed content of How to Remove "index.php" from CodeIgniter 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