Forum Discussion
Add a Trailing Slash to the URL
This is how I do it on v11 (protocol var is from another iRule):
set uri_base [URI::basename [HTTP::path]]
if {$uri_base equals ""} {
The URI::basename is /folder/
} elseif {$uri_base contains "."} {
The URI::basename is *.* file
} else {
HTTP::path "[HTTP::path]/"
HTTP::respond 301 "Location" "${protocol}://[HTTP::host][HTTP::path]"
return
}
- stan_piron9 years ago
Cumulonimbus
Hi Vova,
do not redirect to
but to${protocol}://[HTTP::host][HTTP::path][HTTP::path]there is no need to send to the client the protocol and the server name of the next resource, the client will request with the same protocol and server name as the current one.
with this format, you optimize F5 performance and you prevent rewrite tasks on reverse proxy if there is one with different hostname.
- Kai_Wilke9 years ago
MVP
- Vova_2005209 years ago
Altostratus
Kai, yep, that's the one :)
Stanislas, thanks, will keep that in mind.
- RiverFish8 years ago
Altostratus
Vova, so your iRule adds a trailing slash unless it contains a folder or a file? I have to convert this Microsoft rewrite rule into an iRule and I think your iRule does exactly what I need? The R:1 is whatever is in parenthesis in the "match url" section. "negate" means don't do it.
- Vova_2005208 years ago
Altostratus
Yes, kind of. Check https://clouddocs.f5.com/api/irules/URI__basename.html
 
In some cases you may want to add trailing slash for example in http://myserver.com/something/my.video/ and with the rule above it will not work (my.video is threated as a file although it can be anything).
 
Also as Stanislas Piron mentioned better skip the protocol and host part.
 
- RiverFish8 years ago
Altostratus
Okay, thanks.
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