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 slash for /foo
if {[string first "/" [HTTP::uri] 1] equals "-1" } {
HTTP::redirect "${protocol}://[HTTP::host][HTTP::uri]/"
}
add trailing slash for /foo/bar
if {[string first "/" [string range [HTTP::uri] [string first "/" [HTTP::uri] 1] end] 1] equals "-1"} {
HTTP::redirect "${protocol}://[HTTP::host][HTTP::uri]/"
}
add trailing slash for /foo and /foo/bar
if {([string first "/" [HTTP::uri] 1] equals "-1") or ([string first "/" [string range [HTTP::uri] [string first "/" [HTTP::uri] 1] end] 1] equals "-1")} {
HTTP::redirect "${protocol}://[HTTP::host][HTTP::uri]/"
}
}
Any ideas?