Forum Discussion
Redirect and Referer in iRules
Hi everyone, I've got what I'm sure is a very simple problem. I am deprecating a URL and for a period of time want to do a 301 redirect and insert a "Referer" value on the redirected traffic so I can see how much was hitting it. I've got this so far as an iRule but it's throwing errors when I try to save it:
when HTTP_REQUEST { set refer [HTTP::header "Referer"] {HTTP::header insert “Referer” “foo.bar.com”
HTTP::respond 301 Location https://bar.com[HTTP::uri] } }
Thanks for any and all help! Sean
- What_Lies_Bene1Cirrostratus
You are trying to insert the header into the inbound request and then send the 301 which obviously won't work. Try this instead.
when HTTP_REQUEST { HTTP::respond 301 Location "https://bar.com[HTTP::uri]" Referer "foo.bar.com" }
Also note your "'s seem slightly wrong, have you pasted from MS Word or something? I've corrected them above.
- Sean_Gray_14855Nimbostratus
In the end I went another way. The "referer" piece didn't work so I added a query that I can track:
when HTTP_REQUEST { if { [HTTP::query] ne "" }{ HTTP::respond 301 Location https://foo.com[HTTP::uri]&fromFoobar=true } else { HTTP::respond 301 Location https://foo.com[HTTP::uri]?fromFoobar=true } }
- What_Lies_Bene1CirrostratusOK, cool, glad it's sorted.
- Sean_Gray_14855NimbostratusYeah, thanks for your help!
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com