Forum Discussion
Remove trailing slash
I need to remove any trailing slashes off any url that come in.
www.mydomain.com/category/ - -> www.mydomain.com/category
www.mydomain.com/place/ --> www.mydomain.com/place
etc
I found two examples after doing a search but was not able to follow the logic to mold it to what I needed. I am hoping someone is willing to help me.
Thanks for your help.
7 Replies
- Damion_19248
Nimbostratus
I forgot to mention that I am on 9.4.5.
- Kevin_Stewart
Employee
Something like the following should work:when HTTP_REQUEST { if { [HTTP::uri] ends_with "/" } { HTTP::uri [string trimright [HTTP::uri] "/"] } }
- Kevin_Stewart
Employee
Sorry, the above would actually break the app if the URI was simply "/". Try this instead:when HTTP_REQUEST { if { not ( [HTTP::uri] equals "/" ) and ( [HTTP::uri] ends_with "/" ) } { HTTP::uri [string trimright [HTTP::uri] "/"] } }
- Damion_19248
Nimbostratus
Thanks for you response. I got the following error when I tried to create the rule. Is it compatible with 9.x code or is this 10-11x? - Kevin_Stewart
Employee
There shouldn't be anything in the code that's specific to v10+. Can you isolate which command it's saying is undefined? - Damion_19248
Nimbostratus
I take that back I tried to format it a little by adding additional whitespace and that seems to have broken it. I placed the command just as you typed it and it accepted it. I will test it and let you know the rules. Thanks again for your help. - Saneen_282882
Nimbostratus
Say I need abc.def.com/emp should redirect to https://abc.def.com/redirect/redirect.aspx?src=emp.
Is the below iRule correct ?
when HTTP_REQUEST { HTTP::respond 301 Location "https://abc.def.com/redirect/redirect.aspx?src=[HTTP::uri]" }
How can I remove the "/" before [HTTP::uri] ? I need ?src=emp and not ?src=/emp
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