Forum Discussion
irule issue - URI Case
Dear Forum,
I have a strange issue that below mentioned irule works fine for converting all upper case letters in uri and hostname when http request is received but when https request with any upper case letter is initiated then uri or hostname remains same. I use ssl offloading for https requests. Any idea why it is behaving like this ?
when HTTP_REQUEST {
STREAM::disable
HTTP::uri "[string tolower [HTTP::path]]?[HTTP::query]"
if { [string tolower [HTTP::path]] equals "/" } { if { [HTTP::header "Accept-Language"] starts_with "fr" } { HTTP::respond 301 "Location" "https://www.mylocalnet.com/fr/pages/default.aspx"
} elseif { [string tolower [HTTP::path]] equals "/insidecontent/insidecontent.xml" } { HTTP::respond 301 "Location" "https://insidecontent.mylocalnet.com/insidecontent/insidecontent.xml"
} elseif { [HTTP::path] contains "/hr-dept/" } { HTTP::respond 301 noserver Location "https://[HTTP::host][string map -nocase {hr-dept hr-depart} [HTTP::path]]" } }
when HTTP_RESPONSE {
if { [HTTP::header exists Location] } { HTTP::header replace Location [string map {"http://" "https://"} [string tolower [HTTP::header Location]]] }
if { [HTTP::header Content-Type] contains "text" } {
STREAM::expression { @ @preprod.ccaduae.ae@ @ }
STREAM::enable }
}
5 Replies
- DEJ
Nimbostratus
Hello Ralph,
In a quick review of the syntax (not logic) of the irule, I see you are not utilizing a [string tolower] for{ [HTTP::path] contains "/hr-dept/" }Was that intentional?
- Ralph_David_201
Nimbostratus
You are very right i am just rewriting for this. Would please suggest the complete syntax to make it lower as well as in whole irule any character apart from the uri mentioned if typed in url should be in lower case . That will be very very helpful ? - Stanislas_Piro2
Cumulonimbus
Hi,
You can try this irule:
when HTTP_REQUEST { STREAM::disable set path [string tolower [HTTP::path]] set host [HTTP::host] HTTP::path $path switch -glob $path { "/" { if { [HTTP::header "Accept-Language"] starts_with "fr" } { HTTP::respond 301 "Location" "https://www.mylocalnet.com/fr/pages/default.aspx" } } "/insidecontent/insidecontent.xml" { HTTP::respond 301 "Location" "https://insidecontent.mylocalnet.com/insidecontent/insidecontent.xml" } "*/hr-dept/*" { HTTP::respond 301 noserver Location "https://[HTTP::host][string map -nocase {hr-dept hr-depart} $path]" do not include protocol and host in redirect if hosted on the same base URL. HTTP::respond 301 noserver Location "[string map -nocase {hr-dept hr-depart} $path]" } } when HTTP_RESPONSE { if { [HTTP::header is_redirect]} { Replace absolute URL by relative URL to remove both hostname and protocol HTTP::header replace Location [string map "http://$host/ /" [HTTP::header value Location]] } elseif { [HTTP::header Content-Type] contains "text" } { Replace absolute URL by relative URL to remove both hostname and protocol. This does not rewrite links to others URLs which were rewritten by previous irule STREAM::expression "@http://$host/@/@ " Replace absolute URL by relative URL to remove both hostname and protocol and rewrite URLs. STREAM::expression "@http://$host/@/@ @http://s5.ccaduae.ae@https://s5.ccaduae.ae@ @preprod.ccaduae.ae@www.mylocalnet.com@ @http://www.mylocalnet.com@https://www.mylocalnet.com@" STREAM::enable } } - Ralph_David_201
Nimbostratus
Thanks Darrell for your response. I have tried this but webpage is not loading at all. Please let me share with you complete irule for your information. Currently this irule is providing all the required results as it is written. only issue is in https case when someone types in browser with some capital letters those are not redirected to lowercase. SSL offloading is happening on F5.
when HTTP_REQUEST {
tell server not to compress response HTTP::header remove Accept-Encoding disable STREAM for request flowSTREAM::disable
redirect insidecontent requests to insidecontent siteHTTP::uri "[string tolower [HTTP::path]]?[HTTP::query]"
if { [string tolower [HTTP::path]] equals "/" } { if { [HTTP::header "Accept-Language"] starts_with "fr" } { HTTP::respond 301 "Location" "https://www.mylocalnet.com/fr/pages/default.aspx"
} elseif { [HTTP::header "Accept-Language"] starts_with "en" } { HTTP::respond 301 "Location" "https://www.mylocalnet.com/en/pages/default.aspx" }
} elseif { [string tolower [HTTP::path]] equals "/insidecontent/insidecontent.xml" } { HTTP::respond 301 "Location" "https://insidecontent.mylocalnet.com/insidecontent/insidecontent.xml"
} elseif { [HTTP::path] contains "/hr-dept/" } { HTTP::respond 301 noserver Location "https://[HTTP::host][string map -nocase {hr-dept hr-dapart} [HTTP::path]]"
} elseif { [HTTP::path] contains "/fin-inst/" } { HTTP::respond 301 noserver Location "https://[HTTP::host][string map -nocase {fin-inst fin-institute} [HTTP::path]]"
} elseif { [string tolower [HTTP::uri]] equals "/en/private.xml" } { HTTP::uri "/en-private.xml"
} elseif { [string tolower [HTTP::path]] equals "/fr/private.xml" } { HTTP::uri "/fr-private.xml"
} }
when HTTP_RESPONSE {
catch and replace redirect headersif { [HTTP::header exists Location] } { HTTP::header replace Location [string map {"http://" "https://"} [string tolower [HTTP::header Location]]] }
only look at text dataif { [HTTP::header Content-Type] contains "text" } {
create a STREAM expression to replace any http:// with https:// for content delivery networkSTREAM::expression { @ @ @ @ @ @preprod.mylocal.net@ @ }
enable STREAMSTREAM::enable} }
- JeffRay_129268
Nimbostratus
Hi all, Any idea about this irule . Am i missing something in the code ? Regards.
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