Forum Discussion

SantoshGowda_32's avatar
SantoshGowda_32
Icon for Nimbostratus rankNimbostratus
Feb 26, 2019

Need your assistance to create a F5 redirection rule for /user/login.seam -> /login

Please let me know whether below irule is correct or not:

when HTTP_REQUEST {
if { [HTTP::uri] ends_with "/user/login.seam" } {
    HTTP::uri [string map {"/user/login.seam" "/login"} [HTTP::uri] ]
}
  • Snl's avatar
    Snl
    Icon for Cirrostratus rankCirrostratus

    give a try

    option 1

    when HTTP_REQUEST{
    if { [string tolower [HTTP::uri] ] ends_with "/user/login.seam" } {
      HTTP::uri [string map {"/user/login.seam" "/login"} [HTTP::uri]]
      HTTP::redirect "https://[HTTP::host][HTTP::uri]"
    }
    }
    

    option 2

    when HTTP_REQUEST {
        if { ( [string tolower [HTTP::uri]] ends_with "/user/login.seam" } {
            set uri [HTTP::uri [string map {"/user/login.seam" "" "/login" ""} [HTTP::uri]]]
            HTTP::redirect "https://[HTTP::host]$uri"
        }
    }
    
  • I would use

    HTTP::path
    rather than
    HTTP::uri
    , because the URI could include a query string and hence the comparison would fail.

    when HTTP_REQUEST {
      if { [HTTP::path] ends_with "/user/login.seam" } {
          HTTP::path [string map {"/user/login.seam" "/login"} [HTTP::path] ]
      }
    }
    
  • As Michael noted, you must be careful with upper/lower case comparisons. For completeness' sake, this ought to work in all cases (no pun intended):

    when HTTP_REQUEST {
      if { [string tolower [HTTP::path]] ends_with "/user/login.seam" } {
          HTTP::path [string map -nocase {"/user/login.seam" "/login"} [HTTP::path] ]
      }
    }