For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Ambk25's avatar
Ambk25
Icon for Nimbostratus rankNimbostratus
Oct 28, 2022

Irule ending with trailing slash

I have requirement that If URL is referring to a page that does not end with a "/" then redirect to the same URL ending with a "/" but it should not include below points:

1. ignore all request with Method POST

2. ignore all URLs starting with:

/WebResource.axd

/EPiServer.Forms/

 

3. URLs containing :

a query in the URL (indication is “?”)

URLs containing: /api/

9 Replies

  • 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]/"
        } 
    }
    • Ambk25's avatar
      Ambk25
      Icon for Nimbostratus rankNimbostratus

      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_Stewart's avatar
        Kevin_Stewart
        Icon for Employee rankEmployee
        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]/"
            } 
        }