Part of the EllisLab Network
   
 
Disallowed Character Redirect
Posted: 10 July 2010 04:56 PM   [ Ignore ]  
Grad Student
Avatar
Rank
Total Posts:  57
Joined  03-29-2010

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

Profile
 
 
Posted: 10 July 2010 05:10 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  303
Joined  10-18-2009
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.

 Signature 

Horacio J. Peña
Wallpapers and Images Site: Desktop Wallpapers

Laguna Framework is now very close to its first public (beta) release! Keep in touch for more news

Profile
 
 
Posted: 10 July 2010 05:15 PM   [ Ignore ]   [ # 2 ]  
Grad Student
Avatar
Rank
Total Posts:  57
Joined  03-29-2010

Just tested it…works perfectly. Thanks a lot!

Profile
 
 
Posted: 13 August 2010 11:51 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Avatar
Total Posts:  1
Joined  08-13-2010

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.

 Signature 

http://www.noeljarencio.com/

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 148602 Total Logged-in Users: 33
Total Topics: 103184 Total Anonymous Users: 3
Total Replies: 516555 Total Guests: 280
Total Posts: 619739    
Members ( View Memberlist )