# Redirecting based on cookie value

**URL:** <https://www.ruby-forum.com/t/redirecting-based-on-cookie-value/216418>\
**Category:** NGINX\
**Created:** [February 3, 2012, 8:17pm UTC](https://www.ruby-forum.com/t/redirecting-based-on-cookie-value/216418 "2012-02-03T20:17:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [February 3, 2012, 8:17pm UTC](https://www.ruby-forum.com/t/redirecting-based-on-cookie-value/216418/1 "2012-02-03T20:17:07Z")

</div>

Hi,

I’m want to redirect the user based on the value of a cookie, if  
present.

The scenario is one where there is a “starter” homepage for first time  
users. As soon as users login, I write a cookie with the relative path  
of another homepage. If the cookie is present, I want to redirect the  
user to the cookie value: the relative path. There are multiple cookies  
present in the request, such as session cookies.

I could of course, let the homepage be determined on the session on the  
app server side, but since this is the landing page, I prefer to support  
it with nginx reverse proxy caching. Hence the idea of using cookies to  
redirect the user once he has logged in once.

Any ideas?

Marc

Posted at Nginx Forum:

> **[Redirecting based on cookie value](https://forum.nginx.org/read.php?2,221965,221965#msg-221965)**
>
> Hi, I'm want to redirect the user based on the value of a cookie, if present. The scenario is one where there is a "starter" homepage for first time users. As soon as users login, I write a cookie with the relative path of another homepage....

---

<div class="post-metadata">

**Author:** ![mschipperheyn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@mschipperheyn](https://www.ruby-forum.com/u/mschipperheyn)\
**Post date:** [February 3, 2012, 8:28pm UTC](https://www.ruby-forum.com/t/redirecting-based-on-cookie-value/216418/2 "2012-02-03T20:28:17Z")

</div>

On 3 Fev 2012 19h16 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> cookies.
> 
> I could of course, let the homepage be determined on the session on  
> the app server side, but since this is the landing page, I prefer to  
> support it with nginx reverse proxy caching. Hence the idea of using  
> cookies to redirect the user once he has logged in once.

Use map: [Module ngx\_http\_map\_module](http://nginx.org/en/docs/http/ngx_http_map_module.html)

Here’s a gist that implements a system where a user is redirected to a  
HTTPS host if there’s a session cookie. This is “blind” in the sense  
that it doesn’t capture any value of the cookie. But you can do that  
easily with named captures in map.

> <https://gist.github.com/perusio/1695505>

> Any ideas?

This may be helpful to you.

— appa
