Forum Discussion

Prerak_Tiwari_3's avatar
Prerak_Tiwari_3
Icon for Nimbostratus rankNimbostratus
Sep 29, 2017

iRule to check the referer presense

I am trying to write a iRule to accommodate the following, If the Referer is “mydomain.example.com” then allow the request, if not then check if requested URI is the login page then allow, if not then show 500 error.

when HTTP_REQUEST {
  switch -glob [HTTP::header "Referer"] {
    "https://mydomain.example.com/*" {
      HTTP::redirect [HTTP::header "Referer"]
    }
    "" {
        if{[HTTP::uri] contains "/enter.do"}{
             HTTP::redirect [HTTP::header "Referer"]
        }
        if{!([HTTP::uri] contains "/enter.do")}{
            HTTP::respond 500 content ""
        }
    }
  }
}              

After applying this iRule I am always getting 500. Can someone help me write the correct iRule?

1 Reply

  • Hi,

    don't redirect to referer:

    when HTTP_REQUEST {
      switch -glob [HTTP::header "Referer"] {
        "https://mydomain.example.com/*" {
           do nothing and leave irule
          return
        }
        default {
            if{[HTTP::uri] contains "/enter.do"} {
                 HTTP::redirect [HTTP::header "Referer"]
            } else {
                HTTP::respond 500 content ""
            }
        }
      }
    }