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
}
- Stanislas_Piro2Jan 26, 2017
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_WilkeJan 27, 2017
MVP
- Vova_200520Jan 30, 2017
Altostratus
Kai, yep, that's the one :)
Stanislas, thanks, will keep that in mind.
- RiverFishJan 29, 2018
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_200520Jan 29, 2018
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.
 
- RiverFishJan 29, 2018
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