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"
}
}
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.
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.
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 ?
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.
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.
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.
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.
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
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.
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"
}
}
Your irule can’t be good with IF ELSEIF … There is 301 in the first and redirect in the 2 following.
Please let us know what do you want exactly.
there’s one extra negation in your condition. please look at my previous post for the correct one.
Currently client sends URL request mylocalnet.us which is redirected to https with www code which is code 301. Once redirected to https://www.mylocalnet.us it is offloaded on ltm and request is sent to Web Server. Web server responds 302 https://www.mylocalnet.us/pages/variationroot.aspx which is used for language detection. If FR detected, server replies https://www.mylocalnet.us/fr/pages/default.aspx or with /en per language support. Actual purpose is to avoid multiple redirections on server side and perform these operations on ltm to expedite response time. Sharing with you unmodified code.
when HTTP_REQUEST {
STREAM::disable
redirect atd requests to atd site
if { [string tolower [HTTP::path]] equals "/atd/atd.xml" } {
HTTP::respond 301 "Location" "https://atd.mylocalnet.us/atd/atd.xml"
redirect http://mylocalnet.us to https://www.mylocalnet.us along with any uri
} elseif { [string tolower [HTTP::host]] equals "mylocalnet.us" } {
HTTP::respond 301 "Location" "https://www.mylocalnet.us[string tolower [HTTP::uri]]"
}
switch -glob [string tolower [HTTP::path]] {
"/en/sitemap.xml*" {
HTTP::uri "/en-sitemap.xml"
}
"/fr/sitemap.xml*" {
HTTP::uri "/fr-sitemap.xml"
}
}
}
when HTTP_RESPONSE {
catch and replace redirect headers
if { [HTTP::header exists Location] } {
HTTP::header replace Location [string map {"http://" "https://"} [string tolower [HTTP::header Location]]]
}
only look at text data
if { [HTTP::header Content-Type] contains "text" } {
create a STREAM expression to replace any http:// with https:// for CDN
STREAM::expression {@http://bt.mylocal.ae@https://bt.mylocal.ae@ @www.mylocalnet.us@ @http://www.mylocalnet.us@https://www.mylocalnet.us@}
enable STREAM
STREAM::enable
}
}
OK, something like that. If starting page is “/” check language and redirect to the right URI.
when HTTP_REQUEST {
if { [string tolower [HTTP::path]] equals "/" } {
if { ![HTTP::path] starts_with "/fr" && ([HTTP::header "Accept-Language"] starts_with "fr") } {
HTTP::redirect "https://www.mylocalnet.us/fr/pages/default.aspx"
}
else {
HTTP::redirect "https://www.mylocalnet.us/en/pages/default.aspx"
}
}
}
Matthieu, please ignore my ignorance. If you could adjust in existing rule since else or if is having deprecated irule error so not able to make the changes. my apologies.
Like that
when HTTP_REQUEST {
STREAM::disable
if { [string tolower [HTTP::path]] equals "/" } {
if { ![HTTP::path] starts_with "/fr" && ([HTTP::header "Accept-Language"] starts_with "fr") } {
HTTP::redirect "https://www.mylocalnet.us/fr/pages/default.aspx"
}
else {
HTTP::redirect "https://www.mylocalnet.us/en/pages/default.aspx"
}
}
switch -glob [string tolower [HTTP::path]] {
"/en/sitemap.xml*" {
HTTP::uri "/en-sitemap.xml"
}
"/fr/sitemap.xml*" {
HTTP::uri "/fr-sitemap.xml"
}
}
}
when HTTP_RESPONSE {
catch and replace redirect headers
if { [HTTP::header exists Location] } {
HTTP::header replace Location [string map {"http://" "https://"} [string tolower [HTTP::header Location]]]
}
only look at text data
if { [HTTP::header Content-Type] contains "text" }
create a STREAM expression to replace any http:// with https:// for CDN
STREAM::expression {@http://bt.mylocal.ae@https://bt.mylocal.ae@ @www.mylocalnet.us@
@http://www.mylocalnet.us@https://www.mylocalnet.us@}
enable STREAM
STREAM::enable
}
}
I have applied the irule and below is the result. Not sure where the logic is not getting matched in it. Good thing is Loop is stopped but i see only one Get request in a debug after which loop breaks and aborted and redirected to https by ltm . Web page not found in browser . Below is output for your reference.
URLProtocolMethodResultTypeReceivedTakenInitiatorWaitStartRequestResponseCache read
http://mylocalnet.us/HTTPGET301143 B94 msnavigate0781600234
https://www.mylocalnet.us/HTTPS(Aborted)0 B187 msnavigate9418700047
Details of Above Messages:
Request
--------------------------
Request GET / HTTP/1.1
Accept text/html, application/xhtml+xml, */*
Accept-Language fr,en;q=0.7,en-US;q=0.3
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding gzip, deflate
Host mylocalnet.us
Connection Keep-Alive
Cache-Control no-cache
Response
--------------------------
Response HTTP/1.0 301 Moved Permanently
Location https://www.mylocalnet.us/
Server BigIP
Connection Keep-Alive
Content-Length 0
OK, the redirection is done by another iRule I suppose. On Virtual Server port 80. When connection arrives on 2nd Virtual Server port 443, you see a Aborted ???
I made a mistake. Try this by getting https://www.mylocalnet.us/ with an FR and an EN browser.
when HTTP_REQUEST {
STREAM::disable
if { [string tolower [HTTP::path]] equals "/" } {
if { [HTTP::header "Accept-Language"] starts_with "fr" } {
HTTP::redirect "https://www.mylocalnet.us/fr/pages/default.aspx"
}
else {
HTTP::redirect "https://www.mylocalnet.us/en/pages/default.aspx"
}
}
switch -glob [string tolower [HTTP::path]] {
"/en/sitemap.xml*" {
HTTP::uri "/en-sitemap.xml"
}
"/fr/sitemap.xml*" {
HTTP::uri "/fr-sitemap.xml"
}
}
}
when HTTP_RESPONSE {
catch and replace redirect headers
if { [HTTP::header exists Location] } {
HTTP::header replace Location [string map {"http://" "https://"} [string tolower [HTTP::header Location]]]
}
only look at text data
if { [HTTP::header Content-Type] contains "text" }
create a STREAM expression to replace any http:// with https:// for CDN
STREAM::expression {@http://bt.mylocal.ae@https://bt.mylocal.ae@ @www.mylocalnet.us@
@http://www.mylocalnet.us@https://www.mylocalnet.us@}
enable STREAM
STREAM::enable
}
}
Matthieu,
You are simply a GENIUS guy :). Very Very Thanks for your extra ordinary and superb support. Very much impressed. Hats Off. I have tested it and it worked like a magic
.Once again thanks.