CodeIgniter项目.htaccess部署问题:本地正常服务器失效
Hey there! Let's figure out why your .htaccess works locally but fails to hide index.php on your server at sindangasih-server.com/receiving. The root issue is almost always misconfigured paths for your subdirectory setup—here's how to fix it step by step:
1. Update Your .htaccess File
Your current RewriteBase / points to the server's root, but your project lives in the /receiving subdirectory. Adjust the rules to match your project's actual path:
RewriteEngine On # Point directly to your project's subdirectory RewriteBase /receiving/ # Skip routing for existing files/directories RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Route all other requests to index.php (removed leading slash to fit subdir structure) RewriteRule ^(.*)$ index.php?/$1 [L]
2. Tweak CodeIgniter's Config Settings
Make sure your application/config/config.php aligns with your server setup:
// Set the full base URL including the subdirectory $config['base_url'] = 'https://sindangasih-server.com/receiving/'; // Empty this value to remove index.php from URLs $config['index_page'] = '';
3. Verify Server Environment Requirements
If the above changes don't resolve the issue, check these server-side settings:
- Enable mod_rewrite: Confirm Apache's
mod_rewritemodule is active. You can check this via your hosting control panel (like cPanel's "Apache Modules" section) or by creating aphpinfo.phpfile and searching for "mod_rewrite". - Allow .htaccess Overrides: Your server's Apache config (httpd.conf or virtual host file) needs
AllowOverride Allset for the/receivingdirectory. Without this, the server will ignore your .htaccess rules entirely. - Check File Permissions: Ensure your
.htaccessfile has correct permissions (usually644) so the server can read it.
Quick Test to Confirm .htaccess is Active
To check if your server is even reading the .htaccess file, add this line temporarily at the top:
Deny from all
If you get a 403 Forbidden error when visiting your site, that means .htaccess is active. If not, you'll need to reach out to your hosting provider to fix the server configuration.
内容的提问来源于stack exchange,提问作者Ifadak

