Forum Discussion

trx's avatar
Nov 14, 2009

NOT start with

Hello All,

 

Does anyone know the syntax for using "NOT start with" when doing a comparison with the URI?

 

 

ex)

 

This should do a 301 redirect if the URI does NOT start with "/Solutions Guide" and

 

starts with "Solutions" or "solutions"

 

if { !([HTTP::uri] starts_with "/Solutions Guide") and (([HTTP::uri] starts_with "/Solutions") or

 

([HTTP::uri] starts_with "/solutions")) } {

 

HTTP::respond 301 Location "http://[HTTP::host]/erp/Solutions"

 

log local0. "------301 redirect to Solutions VCM page.-----"

 

return

 

}

 

 

This code above does NOT work for some reason. What am I doing wrong?

 

 

Thanks!

 

 

Regards,

 

TRX
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Hi Trx,

    not and ! are the same in iRules. A URI can't have a literal space in it--it must be URL encoded to %20.

    You could use a switch statement to do this:

     
     when HTTP_REQUEST { 
      
         Check the requested URI 
        switch -glob [HTTP::uri] { 
      
           /[sS]olutions { 
      
              log local0. "[IP::client_addr]:[TCP::client_port]: Matched /solutions check." 
              if {! ([HTTP::uri] starts_with "/Solutions%20Guide") }{ 
      
         log local0. "[IP::client_addr]:[TCP::client_port]: Did not match /Solutions%20Guide" 
         HTTP::respond 301 Location "http://[HTTP::host]/erp/Solutions" 
      } 
           } 
        } 
     } 
     

    Aaron