Forum Discussion
f5_user_7996
Nimbostratus
Aug 08, 2012redirection loop
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.
6 Replies
- Gbps_31870
Nimbostratus
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 - f5_user_7996
Nimbostratus
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 }] - Gbps_31870
Nimbostratus
Hi F5_user,
Sorry for that, just add one open bracket { after HTTP_REQUEST, and a close bracket } at the end of the iRule. - avi123_184259
Nimbostratus
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" } }
- Stanislas_Piro2
Cumulonimbus
Hi avi123,
in
path ishttp://www.test.com/en-us/
is a fragment identifier and is not part of pathen-usare you sure the fragment is sent to the F5? look this thread for more info.
- avi123_184259
Nimbostratus
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.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
