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

Codeigniter v3.1.10修改URL含特殊字符未显示预期错误求助

Fix: CodeIgniter 3.1.10 Throws Exception Instead of Showing "Disallowed URI Characters" Error

Hey there, I’ve dealt with this exact problem in CI 3.1.10 before. Let’s walk through the most common fixes:

1. Check Error Display Configuration

First, head to your application/config/config.php and verify these settings—they control how CI shows errors instead of throwing raw exceptions:

  • $config['display_errors']: Make sure this is set to TRUE. If it’s FALSE, CI won’t render the friendly error page and might default to a PHP exception instead.
  • $config['log_threshold']: Set this to at least 1 (not 0). A threshold of 0 disables error logging entirely, which can break the expected error flow.

2. Verify the URI Filter Logic

CI’s default behavior for invalid URI characters lives in system/core/URI.php in the _filter_uri() method. It should call show_error() to display that specific error message. If someone modified this file (not recommended, by the way!) to throw an exception instead, that’s your issue.

Check that the method has this block:

if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '|'))."]+$|i", $str))
{
    show_error('The URI you submitted has disallowed characters.', 400);
}

If it’s using throw new Exception() or similar, revert it to the original show_error() call.

3. Disable Custom Error Hooks (Temporarily)

If your project uses custom hooks (in application/config/hooks.php) for error handling, they might be overriding CI’s default error display. Try commenting out all hook configurations and test again—if the friendly error comes back, you’ll know one of your hooks is interfering.

4. Check Your Environment Setting

If you’re running in production mode ($config['environment'] = 'production'), CI suppresses detailed error messages by default. Switch to development temporarily to test:

$config['environment'] = 'development';

Just remember to switch back to production once you’re done troubleshooting!

Quick Recap

9 times out of 10, this is either an error display config issue or a modified core file/hook overriding CI’s default behavior. Work through these steps, and you should get that expected error message back instead of exceptions.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 08:18:44