Forum Discussion
Irule ending with trailing slash
Perhaps something like this:
when HTTP_REQUEST {
if { not ( [HTTP::uri] ends_with "/" ) && \
not ( [HTTP::method] eq "POST" ) && \
not ( [HTTP::uri] starts_with "/Webresources.axd" ) && \
not ( [HTTP::uri] starts_with "/EPiServer.Forms/" ) && \
not ( [HTTP::uri] contains "?" ) && \
not ( [HTTP::uri] contains "/api/" ) } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]/"
}
}
Hi Kevin,
Thnk you very much for your reply. We have also created below irule ( with one more requirment --- If any letter in the URL contains upper case then redirect to a strict lower case version of the same URL):
when HTTP_REQUEST {
if { [HTTP::uri] ne [string tolower [HTTP::uri]] } { HTTP::respond 301 noserver Location [string tolower [HTTP::uri]] }
if { not ( [HTTP::uri] ends_with "/" ) and ! ([class match [string tolower [HTTP::path]] ends_with /DMZ/extensions]) and (! ([HTTP::uri] contains "/api/") or ! ([HTTP::uri] contains "/WebResource.axd") or !([HTTP::uri] contains "/EPiServer.Forms/") or !([HTTP::uri] contains "?") )} { HTTP::respond 307 Location "[HTTP::uri]/" }
}
In this irule we want to ignore all post method request which should not redirect, so let us know how we can achive this condition.
- Kevin_StewartOct 31, 2022Employee
when HTTP_REQUEST { if { [HTTP::uri] ne [string tolower [HTTP::uri]] } { HTTP::redirect "https://[HTTP::host][string tolower [HTTP::uri]]" } elseif { not ( [HTTP::uri] ends_with "/" ) && \ not ( [HTTP::method] eq "POST" ) && \ not ( [HTTP::uri] starts_with "/Webresources.axd" ) && \ not ( [HTTP::uri] starts_with "/EPiServer.Forms/" ) && \ not ( [HTTP::uri] contains "?" ) && \ not ( [HTTP::uri] contains "/api/" ) } { HTTP::redirect "https://[HTTP::host][HTTP::uri]/" } }
- Ambk25Nov 02, 2022Nimbostratus
Hi Kevin,
Thanks for your response. We have tested this and fulfilling our requirement but only one problem.
We want to ignore all post method request which should not redirect for first condition i.e. upper to lower case redirection. That means all post methods should not convert to lower case and should not get trail slash. So let us know how we can achieve this condition in existing irule.
- Kevin_StewartNov 02, 2022Employee
when HTTP_REQUEST { if { ( [HTTP::method] ne "POST" ) and ( [HTTP::uri] ne [string tolower [HTTP::uri]] ) } { HTTP::redirect "https://[HTTP::host][string tolower [HTTP::uri]]" } elseif { not ( [HTTP::uri] ends_with "/" ) && \ not ( [HTTP::method] eq "POST" ) && \ not ( [HTTP::uri] starts_with "/Webresources.axd" ) && \ not ( [HTTP::uri] starts_with "/EPiServer.Forms/" ) && \ not ( [HTTP::uri] contains "?" ) && \ not ( [HTTP::uri] contains "/api/" ) } { HTTP::redirect "https://[HTTP::host][HTTP::uri]/" } }
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