Codeigniter v3.1.10修改URL含特殊字符未显示预期错误求助
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 toTRUE. If it’sFALSE, CI won’t render the friendly error page and might default to a PHP exception instead.$config['log_threshold']: Set this to at least1(not0). A threshold of0disables 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

