Forum Discussion
Append text to a URI
Hi Guys,
I am currently trying to append a "/" at the end of a URI provided that the user himself did not include this in the first place.
I am currently using the below iRule:
when HTTP_REQUEST { if { [HTTP::path] equals "/test" } { HTTP::redirect "//sample.domain.com/test/"} }
However I would like to make this more generic and be able to append the "/" at the end of every URI, provided that the user did not include this him/herself.
5 Replies
- nathe
Cirrocumulus
What about this as your if statement?
if { not [HTTP::uri] ends_with "/" } {Hope this helps,
N
- Kevin_Davies_40
Nacreous
Ok this will do what you need. You do not need to specify the entire host as the browser will use the existing site name if you only supply just the URI in the redirect.
when HTTP_REQUEST { if {!([HTTP::path] ends_with "/")} { HTTP::path "[HTTP::path]/" HTTP::redirect [HTTP::uri] } } - Kevin_Davies_40
Nacreous
If any of the below posts have provided a solution to your issue, please indicate so by clicking the tick to the left of them. This gives feedback and recognition to the volunteers who responded to your issue. - Arie
Altostratus
Is there a chance that client requests specify a file (e.g. /index.html, /contact.php)? If so, you won't want to add a slash to those.
- Kevin_Davies_40
Nacreous
Yes good catch. Use this updated iRule
iRule to add a slash to requests when HTTP_REQUEST { skip files if {[HTTP::path] contains "."} { return } already ends in a slash if {[HTTP::path] ends_with "/"} { return } HTTP::path "[HTTP::path]/" HTTP::redirect [HTTP::uri] }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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