Forum Discussion

Sam_Parkes_1110's avatar
Sam_Parkes_1110
Icon for Nimbostratus rankNimbostratus
Dec 01, 2006

404 redirect based on URI

Hi,

 

I'm having trouble getting this iRule to work, just needs a simple redirect if a 404 is received but only if a specific URI is requested, I'm pretty new to this so sorry if it simple. What am I doing wrong?:

 

 

when HTTP_REQUEST {

 

[HTTP::uri] contains "folder/folder2"

 

}

 

when HTTP_RESPONSE {

 

if { [HTTP::status] contains "404"} {

 

HTTP::redirect "http://www.mysite.com/"}

 

}

 

 

Thanks,

8 Replies

  • You'll want to store the URI in a session varaible and then access it in the response. I'm not sure what you were getting at with the comparison in the HTTP_REQUEST event without an if around it...

    Something like this should work for you

    when HTTP_REQUEST {
      set the_uri [HTTP::uri]
    }
    when HTTP_RESPONSE {
      if { ([HTTP::status] equals "404") && ($the_uri equals "/folder/folder2") } {
        HTTP::redirect "http://www.mysite.com"
      }
    }

    -Joe
  • Many thanks to you Joe - this is working perfectly now.

     

    Regarding the HTTP_REQUEST comparison, it was simply my lack of experience with iRules, but I understand why I have to save that info to a variable now.

     

    Once again thank-you,

     

    Sam.
  • I have an almost identical code block

     

    when HTTP_REQUEST { 
       set uri [string tolower [HTTP::uri]] 
       set host [HTTP::host] 
     } 
     when HTTP_RESPONSE { 
       if {([HTTP::status] equals 404) and ($uri equals "/fnf.asp")} { 
         log local0. "404 : http://$host$uri" 
         HTTP::respond 302 Location "http://$host" 
       } 
     }

     

    My 404 is logged to /var/log/ltm

     

    But I don't see a response.

     

    Using http://web-sniffer.net, I don't even see a response code.

     

    Using telnet from the BIGIP shell, I get a disconnect message.
     
       telnet {bigip.ip} 80 
       GET /fnf.asp HTTP/1.0 
       HOST: {fqdn} 
      
       Connection closed by foreign host. 
     

     

     

    I've tried a few different configurations,

     

    HTTP::redirect,

     

    HTTP::respond 200 Content "content",

     

    HTTP::header replace Status 302

     

     

    If I comment out the Respond/Redirect, the client sees the 404 message.

     

    But with that line in there, the client sees nothing.
  • Odd - this rule works for me ver batum:

     

     

    GET /fnf.asp HTTP/1.1

     

    Host: 10.100.100.10

     

    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)

     

    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

     

    Accept-Language: en-us,en;q=0.5

     

    Accept-Encoding: gzip,deflate

     

    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

     

    Keep-Alive: 300

     

    Connection: keep-alive

     

     

    HTTP/1.x 302 Found

     

    Location: http://10.100.100.10

     

    Server: BigIP

     

    Connection: Keep-Alive

     

    Content-Length: 0

     

     

    -Matt

     

  • I can dig it. I don't understand why it's not working either.

     

     

    I've got a ticket open and a webex for tomorrow.
  • could be a bug. it seems like one to me.

     

     

    we spent several hours yesterday afternoon futzing with things until we realized it seems to be related to ASM.

     

     

    we have ASM installed/licensed, but have not yet setup any active profiles.

     

     

    we assigned the generic HTTPClass, and the problem stopped.

     

     

    we created a new, blank, transparent, but ASM enabled HTTPClass, and the problem returned.

     

     

    the problem seems to present itself only to new connections, in which the client did not already have an open connection to the F5.

     

     

    my iRule tries to redirect a specific 404 page with a 302.

     

     

    if the client did not already have an open connection to the F5, the F5 issues a TCP Reset instead of the HTTP 302.

     

     

    if the client did have an open connection to the F5 (the client has already seen an HTTP:200 or HTTP:404), then the F5 will issue the HTTP:302.

     

     

    ...

     

    we're a new install running 10.0.1 b342, HF1
  • Great work and thanks for the excellent description. I'm sure you've already done this, but please be sure and get this information into the case!

     

    -Matt