Forum Discussion
Add a Trailing Slash to the URL
I'm needing to covert an ISAPI rule that adds a trailing slash to the end of a url to an iRule, however the tricky part here is i'll need to add in a few exceptions URLs.
For example if you go to my URL https://secure.mydomain.com/shopping the ISAPI rule auto adds the trailing slash "/" on the end which is fine for nearly all my URIs, but I have a few such as that I do not what the trailing slash to be added.
I have copied the ISAPI rule below for reference of what I'm attempting to do with the LTM and iRules
RewriteCond Host: (.*)
RewriteRule ([^.]+[^/.]) http\://$1$2/ [I,R]
RewriteCond Host: secure\.mydomain\.com
Any thoughts or suggestions?Thanks,
Bob
- The_BhattmanNimbostratusHi Bob,
when HTTP_REQUEST { set bl [findclass [HTTP::uri] $::slashblacklist] if { ([HTTP::uri] eq $bl) and (!([HTTP::uri] ends_with "/")) } { HTTP::uri "[HTTP::uri]/" } }
- Bob_10976NimbostratusBhattman...Thanks for the info. However I had a couple of quick follow up questions..
- Bob_10976Nimbostratus
Guess I spoke to soon, I went and read through the Wiki Class and I see I don't need to create a datagroup...
- hooleylistCirrostratusYou can create a string datagroup in the GUI with your URI tokens that shouldn't have the trailing slash added to. Which LTM version are you running? For 10.x, you'd want to use the class command to look up the requested URI in the datagroup. For 9.x you could use matchclass.
when HTTP_REQUEST { Check if the HTTP path is not in the datagroup and does not already end with a / if { not ([class match [HTTP::path] equals slashblacklist]) and not ([HTTP::path] ends_with "/")} { Append HTTP::path "[HTTP::path]/" } }
- Bob_10976NimbostratusThanks for the reply Aaron.. I'm using 10.2.0 w/ HF1.
- Vova_200520Altostratus
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_Piro2Cumulonimbus
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.
- Vova_200520Altostratus
Kai, yep, that's the one :)
Stanislas, thanks, will keep that in mind.
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