Forum Discussion

david0512_20548's avatar
david0512_20548
Icon for Nimbostratus rankNimbostratus
Oct 27, 2014

irule to rewrite header but respond with 200

Hi All,

Im trying to setup an irule (and struggling :-)) that will perform the following. Upon accessing a site, the request will be rewritten to essentially send the client elsewhere, however rather than providing a 301/302 redirect I need a 200 response to be sent to the client for the initial request.

For example once this rule is setup, a request for a page www.test.com/p/content/ will result in a 200 response for the user. This will work using the URL handling rule sending requests ahead without generating a response to the user and the 200 response coming from www.test.com.

the irule below seems to direct the user correctly but I cant seem to force the 200 response

        When HTTP_REQUEST {

        if { [HTTP::host] contains "www.test." and [HTTP::uri] starts_with "/p/" } {

            HTTP::header replace Host "www.test.com"
}

}

7 Replies

  • shaggy's avatar
    shaggy
    Icon for Nimbostratus rankNimbostratus

    The iRule you have does not generate any type of response itself - it's just sending the user to the pool with a certain HTTP host header. I expect that the pool members are sending the 30x responses, so what do the pool members to see as/in the HTTP request?

     

  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    I'm not sure what you are trying to accomplish. Redirects (301, 302, 307) are standard responses (per RFC 2616) that tell the client to retry the same request but at a different location.

    A 200 (OK) would normally carry a payload (e.g. HTML, image data). It is not intended to instruct the client to treat it like a redirect.

    If you're looking to manipulate the response you can use:

    HTTP::response 200 content "your content here" header X-Custom-Header "custom header value"
    

    Can you explain what you are looking for? Perhaps you are intending to rewrite the request (i.e. keep the same URL in the address bar of the browser but have the BIG-IP send a different payload/page? In that case you'll want to use

    HTTP::uri
    .

  • So this is the requirement from the customer

     

    1. There are currently various "test" domains which are live, such as test.co.uk, test.es, test.com, and so on
    2. A set of pages have been created using an application. This application is currently deployed on IP=1.1.1.1
    3. This application’s pages will be available as www.ultimatetest.com/www.test.com/p/Pages (with each test domain having its own sub-directory)
    4. For this to work successfully, we need the following:
    5. ultimatetest.com DNS to point to 1.1.1.1 (where application resides)
    6. URL handling rule: All requests to www.test.xx/p/$1 to go to www.ultimatetest.com/www.test.es/p/$1
    7. Once this rule is setup, a request for a page www.test.com/p/xxxxx/xxxx will result in a 200 response for the user. This will work using the URL handling rule sending requests ahead without generating a response to the user and the 200 response coming from ultimatetest.com
    • shaggy's avatar
      shaggy
      Icon for Nimbostratus rankNimbostratus
      approximately how many domains will be handled by the iRule, and will it change often?
    • Arie's avatar
      Arie
      Icon for Altostratus rankAltostratus
      When you say "will result in a 200 response" (7), do you mean that the user is expected to retrieve a page/resource from the pool member(s)? If so, this wouldn't be very hard to do in an iRule. Another option would be to access the pages from the actual test domains (without the domain folder name). This is a standard option in mod_rewrite (Apache), but it's also easy to do with an iRule. You could then host all the different domains under a single web server instance.