Home > Article > Backend Development > How to Remove "index.php" from URLs in CodeIgniter?
Problem:
For a beginner using CodeIgniter, removing "index.php" from URLs while accessing pages like "about" (e.g., "localhost/ci/about") remains elusive. Despite experimenting with configurations and searching for solutions, the desired functionality is still not achieved.
Answer:
To resolve this issue and clean up URL rewrites, follow these steps:
1. Configuration in application/config.php:
2. .htaccess in the root directory:
Create a .htaccess file in the root directory of your CodeIgniter installation with the following content:
RewriteEngine on RewriteCond !^(index\.php|resources|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/ [L,QSA]
3. Enabling the rewrite engine in Apache (if not already enabled):
After completing these steps, you should now be able to access your pages without the "index.php" in the URL. For example, "localhost/ci/about" should successfully load the "about_page.php" view.
The above is the detailed content of How to Remove "index.php" from URLs in CodeIgniter?. For more information, please follow other related articles on the PHP Chinese website!