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:
Additional Notes:
If accessing a page via "localhost/ci/about" fails, consider:
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!