Rewrite url based on cookie

Igor Sysoev is at rambler-co.ru
Wed Jan 24 09:21:36 MSK 2007


On Wed, 24 Jan 2007, Jason B wrote:

> Is it possible to rewrite a url based on a cookie value?
>
> In apache it might look like this:
>
> RewriteRule ^index.html$ index%{HTTP_COOKIE['cookieName']}.html

your case:

       location = /index.html  {
           set  $name  "";

           if ($http_cookie ~ "cookieName=([^;]+)(?:;|$)") {
               set  $name  $1;
           }

           index  index$name.html;
       }

or more generic:

       location /  {
           set  $name  "";

           if ($http_cookie ~ "cookieName=([^;]+)(?:;|$)") {
               set  $name  $1;
           }

           index  index$name.html;
       }


Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list