Forum Discussion

trx's avatar
Apr 25, 2011

Response redirect ONLY if browser URI gives an 404 error

Hello All,

How does one redirect to an external URL in the response ONLY if the URI in the browser returns a 404?

 

 

 

ex) When you hit a page and the URL in the browser is "http://xyz.com/xyz". You ONLY want to redirect if

 

"http://xyz.com/xyz" returns a 404. What you do NOT want is if a image request "http://xyz.com/imagexyz" within the page

 

returns a 404 and the response event redirect the user.

 

 

 

1) request --> "http://xyz.com/xyz" // return 404

 

2) request --> "http://xyz.com/imagexyz" // return 404

 

3) response --> redirect to external URL

 

 

 

1) request --> "http://xyz.com/xyz" // return 200

 

2) request --> "http://xyz.com/imagexyz" // return 404

 

3) response --> NO redirect happens

 

 

 

 

Hopefully that made sense.

 

 

 

Thank you in advance.

 

 

 

Regards,

 

TRX

 

8 Replies

  • Hi TRX,

     

     

    If you send a 404 in response to an image, the browser should just not display the image. It shouldn't cause the page which referenced the object to be redirected.

     

     

    Do you have more examples of URIs you would want to redirect and ones you wouldn't? Or could you implement this logic based on content-types? Which LTM version are you trying to do this on?

     

     

    Aaron
  • Hello Aaron,

    I would ONLY redirect the user IF the URL in the browser returns a 404. All the referenced URLs within the page should NOT cause a redirect.

     

    Is there a way to determine if the ONLY the browser URL returns a 404 or NOT?

     

     

     

    Hope that made sense.

     

     

     

    Regards,

     

    TRX

     

  • i am confused. how can we differentiate 1 and 2?

     

    1) request --> "http://xyz.com/xyz" // return 404

     

    2) request --> "http://xyz.com/imagexyz" // return 404

     

     

    for example, is this condition 1?

     

    curl -I http://10.10.70.110/abc

     

    HTTP/1.1 404 Not Found

     

    Date: Fri, 10 Jun 2011 20:20:45 GMT

     

    Server: Apache/2.0.59 (rPath)

     

    Vary: Accept-Encoding

     

    Content-Type: text/html; charset=iso-8859-1

     

     

    what is condition 2?
  • thanks for explanation.

     

     

    as Aaron mentioned, browser won't redirect image. it just doesn't display the image.

     

     

     

    If you send a 404 in response to an image, the browser should just not display the image. It shouldn't cause the page which referenced the object to be redirected.

     

     

     

    [root@orchid:Active] config b virtual bar list

     

    virtual bar {

     

    snat automap

     

    pool foo

     

    destination 172.28.17.88:http

     

    ip protocol tcp

     

    rules myrule

     

    profiles {

     

    http {}

     

    tcp {}

     

    }

     

    }

     

    [root@orchid:Active] config b rule myrule list

     

    rule myrule {

     

    when HTTP_RESPONSE {

     

    if {[HTTP::status] eq 404} {

     

    HTTP::redirect "http://www.google.com"

     

    }

     

    }

     

    }

     

     

    there is dog.gif in index.html and i renamed it. when browsing the index.html, even browser got redirect but it just didn't display the image.

     

     

    GET /dog.gif HTTP/1.1

     

    Accept: */*

     

    Referer: http://172.28.17.88/

     

    Accept-Language: en-US

     

    User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MS-RTC LM 8; InfoPath.3; .NET4.0C; .NET4.0E)

     

    Accept-Encoding: gzip, deflate

     

    Host: 172.28.17.88

     

    Connection: Keep-Alive

     

    Cache-Control: no-cache

     

     

    HTTP/1.0 302 Found

     

    Location: http://www.google.com

     

    Server: BigIP

     

    Connection: Keep-Alive

     

    Content-Length: 0
  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus
    To clarify, I assume that you want the redirect only if the web server returns a 404? You mentioned the browser (client), but it sounds like you want to intercept 404s.

     

     

    We had this requirement years ago. Digging up some old code, here's how I handled it:

     

     

     

    when HTTP_RESPONSE {

     

     

    if { ([HTTP::status] equals "404") } {

     

     

     

     

    HTTP::redirect ...

     

     

     

     

     

  • Posted By trx on 06/11/2011 12:50 AM

     

    I think this is better if I show an image of the browser. I only care if the 1 URL returns a 404 and do NOT care if the relative image URL 2 returns a 404.

     

    If 1 returns a 404, then redirect to custom 404 page.

     

    If 1 returns a 200, but 2 returns a 404, do NOT redirect anywhere.

     

     

    So the goal is to get a hold of the 1 URL and check if it returns a 404 or NOT.

     

    Hi,

     

     

    maybe there is a misconception how the LB works in this context.

     

     

    Let me explain what I mean: The browser loads the inital page, which contains HTML code. Within that HTML code there are references to images, css, javascript, etc. The browser then requests that content, one by one. That's all totally unrelated HTTP requests for the LB. Thus, the LB has no idea what parts (images, etc.) belong to one web page. The browser knows that, but not the LB. So, there is no easy way to intercept 404 errors if multiple conditions have to apply (as you described).

     

     

    Actually it's up to you to tell the LB every single URL where you want to catch 404 errors (which are coming from the web server). As I said, there is no easy way to do that conditionally, only if "this and that happend" as well "on that page".

     

     

    Maybe I don't fully understand what you want to do. Why is it important to intercept a 404 error for an image only if another image did not generate a 404??

     

     

    Regards

     

    Kurt Knochner

     

  • Thinking about this, maybe an image is a bad example. What other types of request causes a browsers to redirect for if NOT images? Hi,

     

     

    please read my first post, then this one!

     

     

    Here we go... You say:

     

    ONLY need to redirect IF the host URI returns a 404 and nothing else on the connection:"http://nba.qad.com/finals/2011/index.html"

     

    Well, if the browser get's a 404 for the main page (the one that contains the references to all other parts), it will have no HTML code to parse and thus no idea what to load. So, no images, no css, no nothing. The whole game ends there.

     

     

    In this connection, there will be many requests in the html page (references to images, js, css, etc.)

     

    Yes, but the browser will not know that, as the main page (the one that contains the HTML code with the references to all other parts) returned 404.

     

    IF all the reference requests to images, js, css, etc. returns a 404, the browser

     

    should NOT redirect, but ONLY when the (1 in screenshot) "index.html" itself

     

    returns a 404.

     

    The browser will not be able to load the images, js, css, etc. as there is no information about that!

     

     

    Again, maybe I don't fully understand what you want to do.

     

     

    Regards

     

    Kurt Knochner