我已经阅读了上面的所有评论 - 但我认为您错过了执行此操作的简单方法。
只需重载_filter_uri()
函数,然后做任何你想做的事情:
(将此文件放在 application/core/MY_URI.php 中)
// Normally this is not fully uppercase - but for some reason the URI filename is
Class MY_URI extends CI_URI
{
/**
* Filter segments for malicious characters
*
* @access private
* @param string
* @return string
*/
function _filter_uri($str)
{
if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE)
{
if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $str))
{
// DO SOMETHING HERE LIKE REDIRECT OR CHANGE THE URL
}
}
// Convert programatic characters to entities
$bad = array('$', '(', ')', '%28', '%29');
$good = array('$', '(', ')', '(', ')');
return str_replace($bad, $good, $str);
}