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 $1 !^(index\.php|resources|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [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:
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3