CodeIgniter URL Rewriting Issues: Removing 'index.php' from URLs
CodeIgniter, like most PHP frameworks, allows you to remove 'index.php' from your website's URLs for a cleaner and more user-friendly appearance. This can be achieved through URL rewriting.
To remove 'index.php' from your URLs in CodeIgniter, follow these steps:
Modify Application Configuration:
In the application/config.php file, make the following changes:
$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name'; $config['index_page'] = ''; $config['uri_protocol'] = 'AUTO';
Create .htaccess File:
Create a .htaccess file in the root directory of your application (where your index.php file is located). Paste the following code into the file:
RewriteEngine on RewriteCond !^(index\.php|resources|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/ [L,QSA]
Enable URL Rewriting:
Make sure to replace Your Ci folder_name in the base_url configuration with the actual name of your CodeIgniter installation directory.
Accessing Specific Pages:
After implementing URL rewriting, you should be able to access your pages without the 'index.php' suffix. For example, you can access your 'about' page by visiting localhost/ci/about. Note that you do not need to create an 'about' directory within the 'application' directory.
If you encounter any issues, such as a 500 Internal Server Error, double-check your configuration and ensure that the mod_rewrite module is enabled correctly.
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!