Forum Discussion
Brad_Parker
Feb 01, 2016Cirrus
This is a simple way of doing what you want:
when HTTP_REQUEST {
if {not ([HTTP::path] ends_with "/")}{
HTTP::respond 301 noserver Location "${protocol}:://[HTTP::host][HTTP::path]"
}
}
One thing to mention though your original iRule used HTTP::uri, that will contain query parameters if they exist which would make your redirect look like this, http://some.domain.com/originalUri?parameter1=xyz/.
If you want to account for query parameters you could do this:
when HTTP_REQUEST {
if {not ([HTTP::path] ends_with "/")}{
if {[HTTP::query] ne ""}{
set myuri "[HTTP::path]/?[HTTP::query]"
}
else {
set myuri "[HTTP::path]/"
}
HTTP::respond 301 noserver Location "${protocol}:://[HTTP::host]$myuri"
}
}
- Brad_ParkerFeb 01, 2016CirrusAs Kai mentions below, you will need additional logic to account for files that wouldn't want trailing slashes.