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

CodeIgniter 3.1.6 CRUD练习路由报错404 Page Not Found求助

Troubleshooting the 404 Error When Accessing /stud in CodeIgniter

Hey there, as a fellow CodeIgniter developer, let's walk through fixing this 404 issue you're facing. Let's start with the most common culprits first, since you're working with a CRUD example as a beginner.

1. Fix the Routes Filename (Critical!)

First off, I notice you mentioned your routing file is named route.php—but CodeIgniter's official configuration file for routes is routes.php (with an extra 's'). If you named it route.php, the framework won't load any of your custom routing rules at all. That means it’s falling back to the default welcome controller, which is almost certainly why accessing /stud gives a 404.

Fix: Rename your file from route.php to routes.php in the application/config/ directory.

2. Verify Controller Placement and Naming

Make sure your Stud_controller.php is placed directly in the application/controllers/ folder—this is where CodeIgniter looks for controller files by default.

Also, double-check that the class name matches the filename exactly (case matters on Linux-based servers):

// Stud_controller.php
class Stud_controller extends CI_Controller {
    // ... your existing code
}

Since your filename is Stud_controller.php, the class name Stud_controller is correct here.

3. Adjust the URI Protocol Setting (If Needed)

Your config.php uses REQUEST_URI, which works for most Apache setups, but sometimes switching to AUTO can resolve routing glitches:

// application/config/config.php
$config['uri_protocol'] = 'AUTO';

Try this if fixing the routes filename doesn’t resolve the 404 right away.

4. Confirm Server Setup (Optional for Your Current URL)

You’re accessing the URL with index.php included (http://localhost/testing/index.php/stud), so your .htaccess rules to remove index.php aren’t the issue here. But for future reference, make sure:

  • Apache’s mod_rewrite module is enabled on your server
  • Your Apache site configuration has AllowOverride All set for your testing directory, so the .htaccess rules can take effect

5. Test the Default Route First

To rule out basic framework setup issues, try accessing http://localhost/testing/index.php/welcome. If that loads the default CodeIgniter welcome page, the framework is running correctly, and the problem is definitely tied to your custom routing or controller setup.

Once you fix the routes filename, your $route['stud'] = "Stud_controller"; rule should kick in, and accessing /stud should load the index() method of Stud_controller as expected.

If you still run into issues after these steps, feel free to share more details (like server error logs) and we can dig deeper!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 08:00:29