Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

HTTP referer header redirect

I am trying to come up with a "sorry server" logic for a virtual server. There is no pool behind the VIP and the only time client requests will hit the virtual server is in the case that there is no healthy real servers. The mechanism I will use to provide that is priority group activation and not part of my question. The question I have is the iRule logic that will meet the below requirements.

1) If special client connects with a 'Referer' HTTP header containing value specialsso.special.com the request will be redirected to special-client downpage

2) If generic client connects with a 'Referer' HTTP header containing any other value than above the request will be redirected to generic-client downpage

3) If any client connects without a 'Referer' HTTP header the request will be redirected to generic-client downpage.

Here is what I have so far:

when HTTP_REQUEST { 
if { [HTTP::header exists "Referer"] } {
        if { [HTTP::header Referer] equals "specialsso.special.com" } {
  HTTP::redirect https://www.site.com/special-client/?
            }
            else   {
            HTTP::redirect https://www.site.com/generic-client
            }
        }
else { HTTP::redirect https://www.site.com/generic-client
}

}

Thanks in advance for the response!

-David O.

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

(Untested). You can have simple if-else statement like this:

when HTTP_REQUEST { 
if { ([HTTP::header exists "Referer"]) and ([URI::host [HTTP::header value Referer]] contains "specialsso.special.com") } {
HTTP::redirect https://www.site.com/special-client/
} else {
HTTP::redirect https://www.site.com/generic-client
}
}
0
Comments on this Answer
Comment made 3 months ago by David Oertli 74

I will test this out, with the logic presented here I wonder what will happen with the 3rd test condition when no referer header is present. I will respond back once I test.

0
Comment made 3 months ago by Vijay 4523

If no referer header, the redirect within "else" statement will be used. Slightly modified my iRule. Please, check again.

Using [URI::host [HTTP::header value Referer]] instead of [HTTP::header value Referer]

0
Comment made 3 months ago by David Oertli 74

So I combined the logic of the two scripts and found that the reason the redirect wasn't being thrown in my original script was I was specifying "equals" instead of "contains" I updated my script and it is working now. Thanks so much for the help!

0