Forum Discussion
Approxee
Nimbostratus
Sep 15, 2017ASM - Regex matching of URL with or without final / trailing slash
Hi Fourm,
I have a situation where sometimes the URL is requested with a final slash and sometimes it is not. Both URIs serve the content without a 301 redirect to the prefered URL - they both ...
Kai_Wilke
MVP
Apr 01, 2019Hi GreeceMonkey,
I'm using the iRule below to add trailing slashes to make ASM policie configuration more comfortable.
when HTTP_REQUEST {
switch -glob -- [string tolower [HTTP::path]] "*.asmx*" - \
"*.json*" - \
"/_*" - \
"*/_layout*" - \
"*/_vti_bin*" - \
"*.svc/*" {
if { $debug } { log -noname local0. "$log_prefix The HTTP::path contains a blacklisted string. Skipping \"Add_Slash_to_Folders\" Manipulation." }
} default {
switch -glob -- [URI::basename [HTTP::path]] "" {
if { $debug } { log -noname local0. "$log_prefix The URI::basename is a /Folder/." }
} "*.*" {
if { $debug } { log -noname local0. "$log_prefix The URI::basename is a *.* File." }
} default {
if { $debug } { log -noname local0. "$log_prefix The URI::basename is a /Folder (without trailing slash). Adding a trailing slash to the URI::basename." }
HTTP::path "[HTTP::path]/"
}
}
}
Cheers, Kai
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