Rewrite url based on cookie

Jason B jasjbow at gmail.com
Wed Jan 24 09:43:10 MSK 2007


On 24/01/2007, at 5:21 PM, Igor Sysoev wrote:

> 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/
>

Excellent! :)  Thanks Igor






More information about the nginx mailing list