Forum Discussion

Sunny_81459's avatar
Sunny_81459
Icon for Nimbostratus rankNimbostratus
Sep 16, 2008

HTTP redirect

I need urgent help can some iRle expert write for me?

 

 

Brief:

 

 

currently, if i request https://test.com/groupabc/aarp.jsp is getting redirected to https://test.com/abc/private/xyz.do but as per the code https://test.com/groupabc/aarp.jsp as header referer enabled.

 

 

 

I would like setup redirect, if uri eq "https://test.com/abc/private/xyz.do" and http_refere equals to NULL then it should redirect to https://test.com/groupabc/aarp.jsp

 

 

I have configured the following irule but not working.

 

 

===============

 

when HTTP_REQUEST {

 

if { [string tolower [HTTP::uri]] starts_with "/abc/private/xyz.do" and

 

( $refer_host ne "" ) } {

 

HTTP::redirect "https://test.com/groupabc/aarp.jsp"

 

}

 

else {

 

pool test.com

 

}

 

}

 

 

===============

 

 

 

Following is the sameple rule witch i referred.

 

 

====================

 

class allowed_referers {

 

"www.companya.com"

 

"www.companyb.com"

 

"www.companyc.com"

 

}

 

 

To disallow empty referers remove the ' and $refer_host ne "" ' check

 

 

To drop the request without redirecting to a custom image, replace

 

the HTTP::respond with 'reject'.

 

 

when HTTP_REQUEST {

 

set refer_host [string tolower [URI::host [HTTP::header Referer]]]

 

if { ( [matchclass [HTTP::path] ends_with $::images] ) and

 

( $refer_host ne "" ) and

 

( not [matchclass $refer_host contains $::allowed_referers] ) } {

 

log local0.NOTICE "hotlink detected from host: $refer_host"

 

HTTP::respond 301 "Location" "http://[HTTP::host]/hotlink.gif"

 

}

 

}

 

==============

 

6 Replies

  • I think you need to get the actual value of the Referer header and replace not equal (ne) with eq (equal). Also, HTTP::path would be more accurate if you want to check the path and object in the URI.

     
     when HTTP_REQUEST { 
        if { ([string tolower [HTTP::path]] eq "/abc/private/xyz.do") and ([HTTP::header value Referer] eq "") } { 
           HTTP::redirect "https://test.com/groupabc/aarp.jsp" 
        } else { 
           pool test.com 
        } 
     }  
     

    Aaron
  • Hey Aaron,

     

     

    My requirement is if the request is coming from uri "https://test.com/abc/private/xyz.do" and header refere is equals to NULL then it should redirect to "https://test.com/groupabc/aarp.jsp"

     

     

    I tried your rule but it is not working.

     

     

    Note: In both cases host name is same (test.com)

     

     

    -Sandy

     

  • Hi Sandy,

    Can you try this version with additional logging? The output is written to /var/log/ltm by default. Also, if you have the pool added to the VIP, you can remove the pool statement from the iRule.

     
      when HTTP_REQUEST {  
         log local0. "[IP::client_addr]:[TCP::client_port]: New HTTP request to [HTTP::host], [HTTP::uri] with Referer [HTTP::header value Referer]" 
         if { ([string tolower [HTTP::path]] eq "/abc/private/xyz.do") and ([HTTP::header value Referer] eq "") } {  
            log local0. "[IP::client_addr]:[TCP::client_port]: Matched URI with no Referer. Redirecting client." 
            HTTP::redirect "https://test.com/groupabc/aarp.jsp" 
         } else {  
            log local0. "[IP::client_addr]:[TCP::client_port]: Request okay.  Using default pool." 
         } 
      } 
     

    Aaron
  • Hi,

     

     

    Below is the log i am getting.

     

     

    And looks like it is using the default pool rather then redirect.

     

     

    Can you help?

     

     

    ==============

     

    Sep 18 13:39:47 tmm tmm[1236]: Rule dev.abc : 1.1.1.1:2340: New HTTP request to test.com, /abc/private/xyz.do with Referer

     

    Sep 18 13:39:47 tmm tmm[1236]: Rule dev.abc : 1.1.1.1:2340: Request okay. Using default pool.

     

    Sep 18 13:39:47 tmm tmm[1236]: Rule dev.abc : 1.1.1.1:2340: New HTTP request to test.com, /abc/private/xyz.do?SMSESSION=NO with Referer

     

    Sep 18 13:39:47 tmm tmm[1236]: Rule dev.abc : 1.1.1.1:2340: Request okay. Using default pool.

     

    ==============

     

     

    -Sandy

     

     

  •  
      when HTTP_REQUEST {   
          log local0. "[IP::client_addr]:[TCP::client_port]: New HTTP request to [HTTP::host], [HTTP::uri] with Referer [HTTP::header "Referer"]"  
          if { ([string tolower [HTTP::path]] eq "/abc/private/xyz.do") and ([HTTP::header "Referer"] eq "") } {   
             log local0. "[IP::client_addr]:[TCP::client_port]: Matched URI with no Referer. Redirecting client."  
             HTTP::redirect "https://test.com/groupabc/aarp.jsp"  
          } else {   
             log local0. "[IP::client_addr]:[TCP::client_port]: Request okay.  Using default pool."  
          }  
       }  
     

    Can you try this one ?
  • if it doesn't work, this one:

     
     HTTP::header exists  
       when HTTP_REQUEST {    
           log local0. "[IP::client_addr]:[TCP::client_port]: New HTTP request to [HTTP::host], [HTTP::uri] with Referer [HTTP::header "Referer"]"   
           if { ([string tolower [HTTP::path]] eq "/abc/private/xyz.do") and (not([HTTP::header exists "Referer"])) } {    
              log local0. "[IP::client_addr]:[TCP::client_port]: Matched URI with no Referer. Redirecting client."   
              HTTP::redirect "https://test.com/groupabc/aarp.jsp"   
           } else {    
              log local0. "[IP::client_addr]:[TCP::client_port]: Request okay.  Using default pool."   
           }   
        }   
     

    this one is because i'm not sure what is the behavior when requesting a non existing header.