Forum Discussion
Former Member
Feb 01, 2016check for trailing slash in /foo and /foo/bar
Hi,
I have a case where I want to add a trailing slash if someone hit /foo or /foo/bar. The rules below works but I wonder if it can be optimized:
when HTTP_REQUEST {
add trailing sla...
Kai_Wilke
Feb 01, 2016MVP
Hi Vova V,
I'm using [URI::basename] command to parse the last element of a given HTTP path. But keep in mind that some WebServices (e.g. ".asmx/method" ".json/method) don't like trailing slashes. So you may want to setup some exclusions...
This is the code I'm using for some SharePoint Sites...
when HTTP_REQUEST {
if { [set uri_base [URI::basename [HTTP::path]]] eq "" } then {
if { $debug } { log -noname local0. "The URI::basename is a /Folder/." }
} elseif { $uri_base contains "." } then {
if { $debug } { log -noname local0. "The URI::basename is a *.* File." }
} else {
if { $debug } { log -noname local0. "The URI::basename is a /Folder (without trailing slash)." }
switch -glob -- [string tolower [HTTP::path]] "*.asmx*" - "*.json*" - "/_*" - "*/_layout*" - "*/_vti_bin*" {
if { $debug } { log -noname local0. "The HTTP::path is exempted..." }
} default {
if { $debug } { log -noname local0. "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