Forum Discussion

Johnathan's avatar
Johnathan
Icon for Nimbostratus rankNimbostratus
Jan 17, 2020

Add Referer query to redirect

Having trouble creating an iRule to redirect URL https://example.to to test.domain.com/?__referrer=<data from referrer header>+<remainder of query string if present>

5 Replies

  • when HTTP_REQUEST {
        set referer [ HTTP::header Referer ]
        if { [HTTP::query] != "" } {
            set RedirectUrl "https://test.domain.com/?__referrer=${referer}&[HTTP::query]"
        } else {
            set RedirectUrl "https://test.domain.com/?__referrer=${referer}"
        }
        HTTP::redirect $RedirectUrl
    }

    This should do that for you - the typo in referer is your own

    • Johnathan's avatar
      Johnathan
      Icon for Nimbostratus rankNimbostratus

      Thank Pete,

       

      That is working now. Do you know if the referer header can do URL-encoding? Example:

      referer=https://www.google.com/my_good_stuff?q=foo&bar=baz should be referrer=https%3A%2F%2Fwww.google.com%2Fmy_good_stuff%3Fq%3Dfoo%26bar%3Dbaz

       

      • PeteWhite's avatar
        PeteWhite
        Icon for Employee rankEmployee
        You can use URI::encode with the set referer command which would be [ URI::encode [ HTTP::header Referer ]]