You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何部署CodeIgniter网站至服务器?解决部署后404错误

Hey there, let's walk through why you're getting that 404 error after uploading your CodeIgniter project to the server—this is a super common gotcha, and we can fix it quickly!

Common Issues & Fixes for CodeIgniter 404 After Server Upload

1. Base URL Mismatch (Most Likely Culprit)

Your local setup uses localhost/project_name as the base, but the server needs the actual domain path. This throws off CodeIgniter's routing entirely.

  • Open application/config/config.php
  • Find the $config['base_url'] line and update it to match your server's path:
    $config['base_url'] = 'http://www.domain_name.com/project_name/';
    
    Don't forget the trailing slash—it matters for asset paths and routing.

2. .htaccess Problems or Rewrite Rules

Local servers (like XAMPP/WAMP) often have rewrite enabled by default, but live servers might not. Plus, hidden .htaccess files can get left out when zipping/uploading.

  • First, confirm your project root has an .htaccess file (it's hidden, so make sure you included it in your ZIP). For subdirectory deployments, the rules should look like this:
    RewriteEngine On
    RewriteBase /project_name/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    
  • If you're using Apache, check that mod_rewrite is enabled (ask your host if you're unsure). For Nginx, you'll need to add equivalent rewrite rules to your server block.

3. Case Sensitivity (Linux vs Windows)

Local Windows machines ignore file case, but Linux servers don't. This is a sneaky one!

  • CodeIgniter requires controller filenames to have a capitalized first letter, and the class name must match exactly. For example:
    • Filename: Controller_name.php (first letter capitalized)
    • Class inside: class Controller_name extends CI_Controller
  • If your local filename was controller_name.php (all lowercase), the server won't recognize it—rename it to match the capitalization rule.

4. Incorrect File/Directory Permissions

The server needs access to write to cache and logs folders, and read access to all core files.

  • Set application/cache and application/logs to 755 (or 777 if 755 doesn't work—though 755 is more secure)
  • Set all PHP files to 644 and directories to 755
  • Avoid setting root or system files to 777—that's a major security risk.

5. Missing or Misconfigured Files

Double-check that you uploaded every file from your local project—sometimes hidden files or system folders get skipped when zipping.

  • Verify system/, application/, and index.php are all present in the server's project_name directory
  • Open index.php and confirm $system_path and $application_folder point to the correct relative paths (they should match your local setup if the folder structure is identical)

6. Route Configuration Errors

If your routes are pointing to the wrong controller (or using incorrect case), you'll get a 404 even if everything else is right.

  • Open application/config/routes.php and check your default controller:
    $route['default_controller'] = 'controller_name';
    
  • Make sure the controller name here matches the actual class name (including case)

Quick Troubleshooting Checklist

  • Did you include hidden files like .htaccess in your ZIP upload?
  • Is base_url updated to your server's domain and project subdirectory?
  • Is URL rewriting enabled on your server?
  • Are controller filenames and class names properly capitalized?
  • Do cache/log directories have the right permissions?

内容的提问来源于stack exchange,提问作者Tanmay

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:21:44