Forum Discussion

Singh_74932's avatar
Singh_74932
Icon for Nimbostratus rankNimbostratus
May 01, 2008

302 to 301

I want to write an iRule which will :

 

 

If ( the response from webserver is 302 )

 

 

Then

 

 

convert it to 301 and insert the location of the redirected URL)

 

 

 

Using 9.x

 

 

Any help will be much appreciated.

 

 

Thanks

 

Raj

7 Replies

  • Hi Raj,

    This example should do just that. If there is other info you need to include in the rewritten redirect, you can add it as an additional header or content. See the HTTP::respond wiki page (Click here) for details.

    
    when HTTP_RESPONSE {
        Check if the server response is a 302
       if {[HTTP::status] == 302}{
           Send a 301 response to the client with the Location header value from the server's response
          HTTP::respond 301 Location [HTTP::header value Location]
       }
    }

    Aaron
  • Got it .. but one thing is this 9.x dependent or we can do it in 4.x too ?

     

  • Hi,

     

     

    The iRule engine was redesigned with v9X so an iRule written in 9x is not compatible with 4x
  • Also, in 4.x there isn't an option to check the response status or modify the response sent to the client. You can only issue redirects or specify a pool based on request criteria.

     

     

    Aaron
  • u guys rock !! ..

     

     

    Issue is that in our global infra some are 4.x and some are 9.x so any thing we can do that can run on both ? Or may be this one we can set for 9.x and some thing else for 4.x ?
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    The issue is that with 4.x there is no way to check the traffic coming back from the client. You really need the full-proxy architecture of the 9.x systems to make something like this work.

     

     

    Colin
  • There is an issue with trying to send a response twice in the same response from an iRule using either HTTP::respond or HTTP::redirect. This issue wouldn't affect your ability to send a redirect after the pool member has responded with a redirect.

     

     

    Aaron