# Reverse Proxy/Redirect/Cookie Presence

**URL:** <https://community.f5.com/t/reverse-proxy-redirect-cookie-presence/27397>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [June 17, 2006, 2:58am UTC](https://community.f5.com/t/reverse-proxy-redirect-cookie-presence/27397 "2006-06-17T02:58:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Hillman\_3](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@David\_Hillman\_3](https://community.f5.com/u/David_Hillman_3)\
**Post date:** [June 17, 2006, 2:58am UTC](https://community.f5.com/t/reverse-proxy-redirect-cookie-presence/27397/1 "2006-06-17T02:58:27Z")

</div>

I’m a new user of BIGIP and TCL so please forgive me for the possibly obvious post. Would someone please provide some guidance on what I am doing wrong? Getting all kinds of errors when attempting import.

Requirements:

-Client requests [http://x.com/a](http://x.com/a) and is redirected to [http://y.com/a](http://y.com/a) without the client seeing the change

-Reverse proxy based on URI’s that are redirected to a pool

-Based on the presence of a cookie different URI redirects are available.

```tcl
when HTTP_REQUEST {
HTTP::header replace Host: y.com
set cookie_exists [HTTP::cookie exists WHITECHOCOLATE]
set requested_URI [string tolower [HTTP::uri]]
if {$cookie_exists=="True"} {
switch -glob $requested_URI} {
"/a" {
pool POOLA
} 
"/b" {
pool POOLB
}
"/c" {
pool POOLB
}
"/d*" {
pool POOLA
}
elseif {$cookie_exists=="False"} {
switch -glob $requested_URI} {
/a" {
pool POOLA
} 
"/b" {
pool POOLB
}
"/c" } {
pool POOLB
}
}

```

---

<div class="post-metadata">

**Author:** ![David\_Hillman\_3](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@David\_Hillman\_3](https://community.f5.com/u/David_Hillman_3)\
**Post date:** [June 20, 2006, 1:09am UTC](https://community.f5.com/t/reverse-proxy-redirect-cookie-presence/27397/2 "2006-06-20T01:09:00Z")

</div>

I scrapped some code together and though I would pass it on.

```tcl
when HTTP_REQUEST {
set requested_URI [string tolower [HTTP::uri]]
HTTP::header replace Host: abc.insidecompany.com
if {[HTTP::cookie exists "test"]} {
if { $requested_URI contains "/ltm" or $requested_URI starts_with "ltm" } { 
log local0. "Cookie test exists, redirecting to $requested_URI pool POOLA"
pool POOLA
} elseif {$requested_URI contains "/gtm" or $requested_URI starts_with "gtm" } { 
log local0. "Cookie test exists, redirecting to $requested_URI pool POOLA"
pool POOLA
} elseif { $requested_URI contains "/F5" or $requested_URI starts_with "F5" } { 
log local0. "Cookie test exists, redirecting to $requested_URI pool POOLB"
pool POOLB
} 
}
else {
if { $requested_URI contains "ltm" or $requested_URI starts_with "ltm" } { 
log local0. "Cookie test does not exist, redirecting to $requested_URI pool POOLA"
pool POOLA
} elseif { $requested_URI contains "F5" or $requested_URI starts_with "F5" } { 
log local0. "Cookie test does not exist, redirecting to $requested_URI pool POOLB"
pool POOLB
} 
}
}
when HTTP_RESPONSE {
HTTP::header replace Host: abc.outsidecompany.com
}

```
