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

Ubuntu下XAMPP运行CodeIgniter出现404错误求助

Troubleshooting CodeIgniter 404 Error on Ubuntu XAMPP (Existing Project Only)

Hey JuanF, let's figure out why your existing CodeIgniter app is throwing 404 errors on Ubuntu + XAMPP while new projects work fine. Since fresh setups run without issues, the problem is tied to your app's specific configuration or file setup. Here are step-by-step checks and fixes:

1. Verify CodeIgniter Core Configuration

First, check your app's core config file at application/config/config.php:

  • Ensure $config['base_url'] is set correctly to your project's root URL, e.g.:
    $config['base_url'] = 'http://localhost/your-project-folder/';
    
    Leaving this empty or using an incorrect path can break routing entirely.
  • Set $config['index_page'] to an empty string to let .htaccess handle removing index.php:
    $config['index_page'] = '';
    
  • Adjust $config['uri_protocol'] if needed—Ubuntu's XAMPP sometimes requires REQUEST_URI instead of the default:
    $config['uri_protocol'] = 'REQUEST_URI';
    

2. Check .htaccess Placement, Permissions, and mod_rewrite

  • Location: Make sure your .htaccess file is in your project's root directory (same folder as index.php), not inside the application folder.
  • Permissions: On Ubuntu, file permissions might block Apache from reading the .htaccess. Run this command (replace with your actual project path):
    sudo chmod 644 /opt/lampp/htdocs/your-project/.htaccess
    
  • Enable mod_rewrite: Even if new projects work, double-check that mod_rewrite is enabled in XAMPP's Apache config. Open /opt/lampp/etc/httpd.conf, find and uncomment this line:
    #LoadModule rewrite_module modules/mod_rewrite.so
    
    Remove the # at the start, then restart Apache via the XAMPP control panel.

3. Update Apache's AllowOverride Setting

Apache might be ignoring your .htaccess rules if AllowOverride is set to None. Open /opt/lampp/etc/httpd.conf, locate the directory block for your web root (e.g., <Directory "/opt/lampp/htdocs">), and change:

AllowOverride None

to:

AllowOverride All

Restart Apache after making this change to apply the setting.

4. Check Routing and File Case Sensitivity

Ubuntu is case-sensitive, which is a common pitfall for CodeIgniter apps developed on Windows (which is case-insensitive):

  • Open application/config/routes.php and confirm the default controller is set correctly, with matching case to the controller file. For example, if your controller is Home.php, the route should be:
    $route['default_controller'] = 'Home';
    
  • Verify that all controller and method names match their file names exactly (e.g., UserController.php can't be referenced as usercontroller in URLs or routes).
  • Check for custom routes that might be conflicting with your intended URLs.

5. Test Direct Index.php Access

To isolate whether the issue is with .htaccess or CodeIgniter routing, try accessing your app directly with index.php in the URL:

http://localhost/your-project/index.php/your-controller/your-method
  • If this works, the problem is with .htaccess not being applied—go back to checking Apache's AllowOverride and mod_rewrite settings.
  • If this still throws a 404, the issue is with your controller/method existence, naming, or routing rules.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 03:24:33