Forum Discussion

Rich_L's avatar
Rich_L
Icon for Nimbostratus rankNimbostratus
Mar 28, 2017

iRule to access URI based off specific device type

I have an iRule in place. The behavior requested is to allow access to only three specific URLs and only if accessing from a device type of iPhone or iPod. If accessing it from any other device or browser (PC, Android, IE, Chrome, Firefox, etc...) it should be redirected to an access denied page. If accessing another URI from the iPhone, it should receive the access denied page. Currently, this iRule partially works. It does allow access to the three sites only if the device type is an iPhone/iPod and denies all other types. However, it also allows the iPhone to access any URI for that URL when it should be denied. This is what I need assistance on. Here is the current iRule:


when HTTP_REQUEST { 

if 
            {     
               ([HTTP::header User-Agent] contains "iPhone") or
               ([HTTP::header User-Agent] contains "iPod")  
            }   
            {   
            if
            {   
                ([HTTP::uri] ends_with "/LEAD.jsp") or 
                ([HTTP::uri] ends_with "/INV.jsp") or 
                ([HTTP::uri] ends_with "/mobile_entry.jsp")
              } 
                { 
                                pool oracle_r12uat 
                } else { 
                        HTTP::redirect "https://mysite.com/OA_HTML/access_denied.jsp" 
                       }                                    
} 
}

Any help or suggestions is greatly appreciated!

1 Reply

  • Hi, in a rapid reply, I would do this way:

    when HTTP_REQUEST { 
        if { ([HTTP::header User-Agent] contains "iPhone") or ([HTTP::header User-Agent] contains "iPod") } {
            if { ([HTTP::uri] ends_with "/LEAD.jsp") or 
                 ([HTTP::uri] ends_with "/INV.jsp") or 
                 ([HTTP::uri] ends_with "/mobile_entry.jsp") } {
    
                pool oracle_r12uat
                Exit from here before I redirect unexpectedly
                return
            }
        }
        Redirect when not match any above
        HTTP::redirect "https://mysite.com/OA_HTML/access_denied.jsp" 
    }
    

    Regards.