Forum Discussion
irule based redirection issue
Dear Members, I have a problem of language redirection loop. As per code mentioned below, Preferred Language is detected (i.e fr (french) in browser and redirected by ltm but this redirection goes into loop instead of request forwarded to server to retrieve the page by client. Seems every time ltm gets redirected URL from client it checks language and does same redirection which ends in continuous loop (snippet below of redirection from ltm). While for other preferred language when selected e.g en it works fine as it is a default in rule. It is really painful for me to get rid of this loop and have no idea why it is not working. I need your expertise to help me get rid of this nasty loop. Thanks.
Response HTTP/1.0 302 Found
Location https://www.mylocalnet.us/fr/pages/default.aspx
Server BigIP
when HTTP_REQUEST {
if { [string tolower [HTTP::path]] equals "/atd/atd.xml" } {
HTTP::respond 301 "Location" "https://atd.mylocalnet.us/atd/atd.xml"
} elseif { [HTTP::header "Accept-Language"] starts_with "fr" } {
HTTP::redirect "https://www.mylocalnet.us/fr/pages/default.aspx"
} elseif { [string tolower [HTTP::path]] equals "/" } {
HTTP::redirect "https://www.mylocalnet.us/en/pages/default.aspx"
}
}
19 Replies
- Matt_Dierick
Employee
Hi mate,
It's normal, for every request with Accept-Language FR, LTM will send a redirect. It's a loop. So what ever the URI, if browser is french, you send a redirect.
You have to modify your HTTP_REQUEST event. Let me know what you are expecting with this irule.
- JeffRay_129268
Nimbostratus
Hi Matthieu, thanks for the response and You are right, redirection is normal behavior but i am not sure why it is continuously redirecting if i enable debug in explorer to test language response i see 100+ redirections and at the end request stops with page not found means client browser is receiving ( Response HTTP/1.0 302 Found , Location https://www.mylocalnet.us/fr/pages/default.aspx , Server BigIP ) constantly in response instead of any contents etc while site is operational and working fine when not using irule.
- Matt_Dierick
Employee
Yes, step by step 1. browser sends GET /something with language FR 2. BIGIP sends redirect to https://www.mylocalnet.us/fr/pages/default.aspx 3. browser sends GET https://www.mylocalnet.us/fr/pages/default.aspx with language FR 4. BIGIP sends redirect to https://www.mylocalnet.us/fr/pages/default.aspx --> LOOP 5. LOOP 6. LOOP
Are you seeing that in the browser ?
- JeffRay_129268
Nimbostratus
Very right dear, what you have mentioned is correct , in **Response** i am getting (Location - https://www.mylocalnet.us/fr/pages/default.aspx ) and in **Request** i get ( Request - GET /fr/pages/default.aspx HTTP/1.1 ) and it keeps going on.
- Matt_Dierick
Employee
Make sense. Now let me know what your are expecting from this irule and I will try to find a solution. You can't use JUST the language to make a redirection. You must combine LANGUAGE and something unique like URI.
I mean, if browser if FR and user get / --> redirect to blablalbla.
- JeffRay_129268
Nimbostratus
correct so if client has preferred language set to FR and user types in browser mylocalnet.us then LTM will detect this language and send him FR home page URL https://www.mylocalnet.us/fr/pages/default.aspx and if FR not found will send him default English home page URL https://www.mylocalnet.us/en/pages/default.aspx.
- JeffRay_129268
Nimbostratus
So in next request when client Requests Get /fr/pages/default.aspx or en/pages/default.aspx then ltm will contact server and delivers the contents to the browser.
- KarimBenyelloul
Cirrostratus
Hi JeffRay,
Please keep in mind that everytime your client sends a request the Irule is executed. So if the client sends
GET https://www.mylocalnet.us/fr/pages/default.aspx
Accept-Language FR
He'll be redirected to the same url : https://www.mylocalnet.us/fr/pages/default.aspx . causing the looping
One solution to avoid the looping could be to modify your condition inorder to check if the client isn't already going to /fr/* in which case not redirecting him. something like this
elseif { !([HTTP::path] starts_with "/fr") && [HTTP::header "Accept-Language"] starts_with "fr" )hope it'll help
Karim
- Matt_Dierick
Employee
Jeff,
As Karim said, combine /fr uri and language FR. If URI = /fr and language = FR --> do nothing, that means redirection is already done.
If URI not equal to /fr and language = FR --> redirect.
- JeffRay_129268
Nimbostratus
I have now changed and tried this and with english or french any language when selected, loop has stopped as you expected that is good but it terminates on first request i.e client is redirected to http(s)://(www).mylocalnet.us and no URI is added.
Browser Debug output: http://mylocalnet.us/ HTTP GET 301 https://www.mylocalnet.us/ HTTPS (Aborted) when HTTP_REQUEST { if { [string tolower [HTTP::path]] equals "/atd/atd.xml" } { HTTP::respond 301 "Location" "https://atd.mylocalnet.us/atd/atd.xml" } elseif { ![HTTP::path] starts_with "/fr" && !([HTTP::header "Accept-Language"] starts_with "fr") } { HTTP::redirect "https://www.mylocalnet.us/fr/pages/default.aspx" } elseif { [string tolower [HTTP::path]] equals "/" } { HTTP::redirect "https://www.mylocalnet.us/en/pages/default.aspx" } }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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