Hi all,
Anybody could help me on this scenario
A customer wants to redirect their website with 301 response with the following scenarios.
1) customer.co.nz → http://www.customer.co.nz/Pages/default.aspx
2) www.customer.co.nz → http://www.customer.co.nz/Pages/default.aspx
I was able to sort the first one with this irule:
when HTTP_REQUEST {
if { [string tolower [HTTP::]] equals “customer.co.nz” } {
HTTP::respond 301 location http://www.customer.co.nz/Pages/Default.aspx
}
}
But on the second one when I apply the rule below it says on my browser “redirection loop”
when HTTP_REQUEST {
if { [string tolower [HTTP::]] equals “www.customer.co.nz” } {
HTTP::respond 301 location http://www.customer.co.nz/Pages/default.aspx"
}
}
I’m not sure what’s wrong with the second rule, they are separate irule and both mounted on one virtual server.
Thanks.
Hi,
Try This iRule, it should works with both scenarios.
when HTTP_REQUEST
if {([string tolower [HTTP::host]] contains “customer.co.nz”) and ([HTTP::path] equals “/”)} {
HTTP::respond 301 location http://www.customer.co.nz/Pages/default.aspx
}
or instead of HTTP::respond 301 … you can type HTTP::redirect “http://www.customer.co.nz/Pages/default.aspx” but this redirection will be 302 response instead.
HTH
BR,
Abdul
Hi Abdul,
The rule doesn’t work it’s giving me the error below:
01070151:3: Rule [Trial_irule] error: line 1: [wrong args] [when HTTP_REQUEST ] line 2: [command is not valid in the current scope] [if {([string tolower [HTTP::host]] contains “customer.co.nz”) and ([HTTP::path] equals “/”)} { HTTP::respond 301 location http://www.customer.co.nz/Pages/default.aspx }]
Hi F5_user,
Sorry for that, just add one open bracket { after HTTP_REQUEST, and a close bracket } at the end of the iRule.
Hi Abdul,
I tried same, but still getting into redirect loop. when HTTP_REQUEST { if {([string tolower [HTTP::host]] contains “www.test.com”) and ([HTTP::path] equals “/”)} { HTTP::respond 301 location “http://www.test.com/en-us” } }
Hi avi123,
in
http://www.test.com/en-us
path is
/
en-us
is a fragment identifier and is not part of path
are you sure the fragment is sent to the F5? look this thread for more info.
Hi Stanislas,
Yeah, you are right, en-us is not being sent to F5, which is causing the loop.
Thank you so much for pointing to that.