Welcome Guest, Not a member yet? Register   Sign In
Disallowed Character Redirect
#1

[eluser]treeface[/eluser]
Hello all,

I was curious if there's a simple method of redirecting a disallowed character URL to a 404 page. My current allowed characters regex is the CI default. Thanks
#2

[eluser]Buso[/eluser]
Code:
class MY_URI extends CI_Uri {
    
    public function __construct() {
      
        parent::CI_URI();
        
    }
    
    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)) {
                
                $str = 'non-existent-uri';
                
            }
            
        }
                            
        return $str;
        
    }
}

Basically you return a non-existent uri when you find disallowed characters. Then you let the Router class handle that as a 404.
#3

[eluser]treeface[/eluser]
Just tested it...works perfectly. Thanks a lot!
#4

[eluser]shofe[/eluser]
Hi,

I'm just wondering how this get's called automatically. Because I have added this one and it's not working it is still executing the original URI.




Theme © iAndrew 2016 - Forum software by © MyBB