rewrite rule looping

I’ve got what would seem to be a simple redirect:

I’m trying to take any requests bound for:

http://ads.xyz.com/

and redirect them to:

https://ads.xyz.com/some/stuff.do

The rule I put up was this:

if { [HTTP::host] equals "ads.xzy.com"} { 
 HTTP::redirect "https://[HTTP::host]/some/stuff.do:443" 
 }

but when I watch it through wireshark it just loops endlessly (because the redirect matches the rule itself?)

Can someone help out an F5 newb?

Thanks.

How about this

if { ([HTTP::host] equals "ads.xyz.com") and ([HTTP::uri] ends_with"/") } { 
      HTTP::redirect "https://[HTTP::host]/some/stuff.do" 
 }

Hope this helps

CB

Assuming your rule is applied to the port 80 VIP this shouldn’t be an issue - just make sure you don’t apply the rule to your port 443 VIP.

Also, it looks like you have an extraneous ‘:443’ in the redirect URL. I’m guessing you intend this to be the port, but it should be appended to the Host portion of the URL, not the end of the path. It shouldn’t be needed at all, though since the default port for https is 443 and therefor doesn’t ned to be spec’d at all.

Posted By dsirrine@gmail.com on 02/17/2009 1:45 PM

I’ve got what would seem to be a simple redirect:

I’m trying to take any requests bound for:

http://ads.xyz.com/

and redirect them to:

https://ads.xyz.com/some/stuff.do

The rule I put up was this:

if { [HTTP::host] equals "ads.xzy.com"} {  
 HTTP::redirect "https://[HTTP::host]/some/stuff.do:443"  
 }

but when I watch it through wireshark it just loops endlessly (because the redirect matches the rule itself?)

Can someone help out an F5 newb?

Thanks.

Well the reason for this is that the “Host” will always be “ads.xyz.com”, So every time, it checks this condition, it returns a true and thus the redirect happens.

You can actually verify this on the Wireshark by looking for HTTP 302 packets, you will see the Server name as “BigIP” or a variant of this, so we can be sure that the BIG-IP is redirecting and not the page.

So you have to use the below code

if { ([HTTP::host] equals "ads.xyz.com") and ([HTTP::uri] equals "/") } {  
       HTTP::redirect "https://[HTTP::host]/some/stuff.do"  
  }

This is a very simple solution, you have to note this point that a lot of URI always end with a “/”, so we need to make a perfect match and so you have to use the keyword “equals”

Also, if you want to have a multiple redirect for the same host, you can use a nested loop

if { ([HTTP::host] equals "ads.xyz.com") { 
    if {[HTTP::uri] equals "/"} { 
       HTTP::redirect "https://[HTTP::host]/some/stuff.do" 
    } 
 }

You can actually add a lot of other else if in the inner loop to redirect other pages also.

Hope this helps