Forum Discussion

Pankaj_Kakade_7's avatar
Pankaj_Kakade_7
Icon for Nimbostratus rankNimbostratus
Apr 24, 2015

HTTP Response with iRule

Hello Team

 

I need help to set iRule to respond 404 page not found. If

 

1) HTTP request is https://abc.com irule should respond 404 Page not found 2) HTTP request is https://abc.com/test it should load web page.

 

I tried below iRule but it respond with 404 in both cases

 

when HTTP_REQUEST {if {[HTTP::uri] equals "abc.com"}{ HTTP::respond 404 content "HTTP ERROR 404 Reason:Not Found" Mime-Type "text/html" }

 

1 Reply

  • "I tried below iRule but it respond with 404 in both cases" This does not sound right. Note that the value of URI you're using in your conditional statement is HTTP path + Query. It's not the same thing as URL.

    For your request, use the iRule below:

    when HTTP_REQUEST {
      if {[HTTP::path] equals / }{
        HTTP::respond 404 content "HTTP ERROR 404 Reason:Not Found" Mime-Type "text/html"
        event disable
        TCP::close
      } elseif { [string tolower[HTTP::path]] starts_with /test }{
        return
      }
    }