Forum Discussion
URI to lower case LTM irule issue
Hi Team,
I have a challenge to redirect all uri into lower case. I am able to redirect the URL to lower case but if i type in e.g myweb.net/fR/PAges/DEfauLT.aspx etc it does not redirect to lower case e.g myweb.net/fr/pages/default.aspx. I am trying my best but not sure where actually issue lies. Your help is very much appreciated.
when HTTP_REQUEST {
STREAM::disable
HTTP::path [string tolower [HTTP::path]]
if { [string tolower [HTTP::path]] equals "/" } {
if { [HTTP::header "Accept-Language"] starts_with "fr" } {
HTTP::respond 301 -nocase "Location" "https://www.myweb.net/fr/pages/default.aspx" Strict-Transport-Security "max-age=300
}
elseif { [HTTP::header "Accept-Language"] starts_with "en" } {
HTTP::respond 301 -nocase "Location" "; Strict-Transport-Security "max-age=300" }
} elseif { [string tolower [HTTP::path]] equals "/autodiscover/autodiscover.xml" } {
HTTP::respond 301 "Location" "https://autodiscover.myweb.net/autodiscover/autodiscover.xml"
HTTP::redirect "http://[HTTP::host][string tolower [HTTP::path]][HTTP::query]"
} elseif { [string tolower [HTTP::host]] contains "blog.myweb.net" }{
HTTP::respond 301 noserver "Location" "https://www.myweb.net/en/tech/pages/default.aspx"
} elseif { [string tolower [HTTP::host]] contains "techpage.myweb.net" }{
HTTP::respond 301 noserver "Location" "https://www.myweb.net/en/tech/Pages/techpage.aspx"
}
}
when HTTP_RESPONSE {
HTTP::header remove SPRequestGuid
set cookies [HTTP::cookie names]
foreach aCookie $cookies {
HTTP::cookie secure $aCookie enable
}
if { [HTTP::header exists Location] } {
HTTP::header remove Server
HTTP::header replace Location [string map {"http://" "https://"} [string tolower [HTTP::header Location]]]
}
if { [HTTP::header Content-Type] contains "text" } {
STREAM::expression { @http://s5.mywebnet.net@https://s5.mywebnet.net@ }
STREAM::enable
}
}
- nitass_89166Noctilucent
I am able to redirect the URL to lower case but if i type in e.g myweb.net/fR/PAges/DEfauLT.aspx etc it does not redirect to lower case e.g myweb.net/fr/pages/default.aspx.
where do you want the redirection to be generated? is it server or bigi-ip?
if it is big-ip, i think myweb.net/fR/PAges/DEfauLT.aspx does not match condition in HTTP_REQUEST event because the outer-if is to check whether request path is equal to root (/).
- Ralph_David_201Nimbostratus
Thanks nitass for your response. Redirection should be on F5 side for client requests with Upper case URI to Lower case URI.
- nitassEmployee
I am able to redirect the URL to lower case but if i type in e.g myweb.net/fR/PAges/DEfauLT.aspx etc it does not redirect to lower case e.g myweb.net/fr/pages/default.aspx.
where do you want the redirection to be generated? is it server or bigi-ip?
if it is big-ip, i think myweb.net/fR/PAges/DEfauLT.aspx does not match condition in HTTP_REQUEST event because the outer-if is to check whether request path is equal to root (/).
- Ralph_David_201Nimbostratus
Thanks nitass for your response. Redirection should be on F5 side for client requests with Upper case URI to Lower case URI.
- nitassEmployee
Redirection should be on F5 side for client requests with Upper case URI to Lower case URI.
e.g.
// config [root@ve13a:Active:In Sync] config tmsh list ltm virtual bar ltm virtual bar { destination 172.28.24.10:80 ip-protocol tcp mask 255.255.255.255 pool foo profiles { http { } tcp { } } rules { qux } source 0.0.0.0/0 source-address-translation { type automap } translate-address enabled translate-port enabled vs-index 3 } [root@ve13a:Active:In Sync] config tmsh list ltm rule qux ltm rule qux { when HTTP_REQUEST { if { [HTTP::uri] ne [string tolower [HTTP::uri]] } { HTTP::respond 301 noserver Location http://[HTTP::host][string tolower [HTTP::uri]] } } } // test [root@ve13a:Active:In Sync] config curl -I http://172.28.24.10/fR/PAges/DEfauLT.aspx HTTP/1.0 301 Moved Permanently Location: http://172.28.24.10/fr/pages/default.aspx Connection: Keep-Alive Content-Length: 0 [root@ve13a:Active:In Sync] config curl -I http://172.28.24.10/fr/pages/default.aspx HTTP/1.1 404 Not Found Date: Mon, 25 Dec 2017 08:53:27 GMT Server: Apache/2.2.3 (CentOS) Last-Modified: Fri, 15 Apr 2016 03:55:49 GMT ETag: "418e44-6a-fc825b40" Accept-Ranges: bytes Content-Length: 106 Content-Type: text/html; charset=UTF-8
- Ralph_David_201Nimbostratus
Awesome nitass.From curl output i see it shows to lowercase but i see in browser URI remains in uppercase instead of redirected to lowercase.
- nitassEmployee
you may have to perform further troubleshooting such as tcpdump/ssldump, http analyzer tool or irule logging to see where the problem is.
- Stanislas_Piro2Cumulonimbus
I always recommend path-relative absolute URLs when destination page is on the same service as the current page:
when HTTP_REQUEST { if { [HTTP::uri] ne [string tolower [HTTP::uri]] } { HTTP::respond 301 noserver Location [string tolower [HTTP::uri]] } }
the problem when working with absolute URLs is when a reverse proxy is configured in front of the server with another hostname or scheme, rewriting is required.
- nitass_89166Noctilucent
Redirection should be on F5 side for client requests with Upper case URI to Lower case URI.
e.g.
// config [root@ve13a:Active:In Sync] config tmsh list ltm virtual bar ltm virtual bar { destination 172.28.24.10:80 ip-protocol tcp mask 255.255.255.255 pool foo profiles { http { } tcp { } } rules { qux } source 0.0.0.0/0 source-address-translation { type automap } translate-address enabled translate-port enabled vs-index 3 } [root@ve13a:Active:In Sync] config tmsh list ltm rule qux ltm rule qux { when HTTP_REQUEST { if { [HTTP::uri] ne [string tolower [HTTP::uri]] } { HTTP::respond 301 noserver Location http://[HTTP::host][string tolower [HTTP::uri]] } } } // test [root@ve13a:Active:In Sync] config curl -I http://172.28.24.10/fR/PAges/DEfauLT.aspx HTTP/1.0 301 Moved Permanently Location: http://172.28.24.10/fr/pages/default.aspx Connection: Keep-Alive Content-Length: 0 [root@ve13a:Active:In Sync] config curl -I http://172.28.24.10/fr/pages/default.aspx HTTP/1.1 404 Not Found Date: Mon, 25 Dec 2017 08:53:27 GMT Server: Apache/2.2.3 (CentOS) Last-Modified: Fri, 15 Apr 2016 03:55:49 GMT ETag: "418e44-6a-fc825b40" Accept-Ranges: bytes Content-Length: 106 Content-Type: text/html; charset=UTF-8
- Ralph_David_201Nimbostratus
Awesome nitass.From curl output i see it shows to lowercase but i see in browser URI remains in uppercase instead of redirected to lowercase.
- nitass_89166Noctilucent
you may have to perform further troubleshooting such as tcpdump/ssldump, http analyzer tool or irule logging to see where the problem is.
- Stanislas_Piro2Cumulonimbus
I always recommend path-relative absolute URLs when destination page is on the same service as the current page:
when HTTP_REQUEST { if { [HTTP::uri] ne [string tolower [HTTP::uri]] } { HTTP::respond 301 noserver Location [string tolower [HTTP::uri]] } }
the problem when working with absolute URLs is when a reverse proxy is configured in front of the server with another hostname or scheme, rewriting is required.
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