Forum Discussion
iRule to Add Trailing Slash Except for Extensions
- Jun 04, 2020
Hello,
Considering that the resource will only have the dot char to extensions, I do this way:
when HTTP_REQUEST { if { not ( [HTTP::path] ends_with "/") && not ( [URI::basename [HTTP::uri]] contains "." ) } { # Append slash and keep querystring when it exists HTTP::uri [HTTP::path]/[expr { "[URI::query [HTTP::uri]]" eq {} ? {} : "?[URI::query [HTTP::uri]]" }] } if { [string tolower [HTTP::uri]] starts_with "/apps" } { pool ProxyPass_DEV_pool_2 } else { pool ProxyPass_DEV_pool_1 } }
Where:
- "/apps" will become "/apps/" internally;
- "/apps?param=value" will become "/apps/?param=value" internally;
- "/test.html" and "/test.html?param=value" remais the same.
I hope it helps.
Regards
Hello,
Considering that the resource will only have the dot char to extensions, I do this way:
when HTTP_REQUEST {
if { not ( [HTTP::path] ends_with "/") && not ( [URI::basename [HTTP::uri]] contains "." ) } {
# Append slash and keep querystring when it exists
HTTP::uri [HTTP::path]/[expr { "[URI::query [HTTP::uri]]" eq {} ? {} : "?[URI::query [HTTP::uri]]" }]
}
if { [string tolower [HTTP::uri]] starts_with "/apps" } {
pool ProxyPass_DEV_pool_2
}
else {
pool ProxyPass_DEV_pool_1
}
}
Where:
- "/apps" will become "/apps/" internally;
- "/apps?param=value" will become "/apps/?param=value" internally;
- "/test.html" and "/test.html?param=value" remais the same.
I hope it helps.
Regards
Thanks cjunior! This worked well with only one minor issue. It looks like it is appending the / regardless if it the / is there or not. Is there a way to make the statement to say "if not contains "." AND does not end with "/", to add the "/"?
Thanks!
- cjuniorJun 08, 2020Nacreous
Ops! That passed by my eyes :/.
Thank you for warn me.
I rewrited that condition. Check that out.
- jonathanw84Jun 08, 2020Cirrus
Thank you so much! I was on the right track but I was slightly off. I really appreciate your help. Take care!
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