Forum Discussion

vrajan_97076's avatar
vrajan_97076
Icon for Nimbostratus rankNimbostratus
Sep 12, 2007

How to get the URL of the referrer page?

Hi,

 

 

How do we get the URL of the referrer page using iRules?

 

Like in asp, we can use either the Request.ServerVariables("HTTP_REFERER") or document.referrer for the same. Is there an equivalent for these in iRules?

 

 

Please Help.

 

Thanks

 

4 Replies

  • Hi,

    You can get any HTTP header value with the command 'HTTP::header value HEADER_NAME' command (Click here). Here's an example that logs the value to /var/log/ltm:

    
    when HTTP_REQUEST {
       log local0. "Referer: [HTTP::header value Referer]"
    }

    Aaron
  • The referer header (and any other HTTP header) can easily be modified by a user. Browser plugins like Firefox's tamper data or interception proxies make it very simple to manipulate header values. You might want to reconsider using the referer header value for anything other than reporting purposes. Does the application set a cookie with a session ID, or is there some other way to differentiate users who have logged into the application from those that are accessing the pages directly without having logged in? If so, you might be better off using that as a key for access control.

     

     

    If you do want to stick with the referer header, you would need to pick either the HTTP::respond command or the HTTP::redirect. You can't use both methods in the same event one after another. You could use HTTP::respond and within the response content include text which is displayed to the user and javascript which redirects them after x number of seconds to http://abc.def.com.

     

     

    Also, the referer header will typically be set to the full URL of the referring page. So you might want to use 'contains' instead of 'ends_with'.

     

     

    Aaron
  • Sorry, but i'm new to this, just to confirm if this will work ???

     

     

    when HTTP_REQUEST

     

    {

     

    if { [string tolower [HTTP::header value Referer]] contains "abc.def.com" }

     

    {

     

    do nothing

     

    }

     

    else

     

    {

     

    HTTP::respond 200 content " "

     

    }

     

    }

     

     

    Thanks again.
  • The only problem I see is the embedded quotes in your string. You can either escape them with backslashes "...\"..." or use single quotes which will work with javascript as well. You can also simplify it a bit to elimiate the else clause though.

    This should work for you:

    when HTTP_REQUEST
    {
      if { ! ([string tolower [HTTP::header value Referer]] contains "abc.def.com") } {
      HTTP::respond 200 content "  "
      }
    }

    -Joe