# Cookies path rewrite

**URL:** <https://www.ruby-forum.com/t/cookies-path-rewrite/151736>\
**Category:** NGINX\
**Created:** [October 24, 2008, 11:04pm UTC](https://www.ruby-forum.com/t/cookies-path-rewrite/151736 "2008-10-24T23:04:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ondrej\_Jombik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a698b9/32.png) [@Ondrej\_Jombik](https://www.ruby-forum.com/u/Ondrej_Jombik)\
**Post date:** [October 24, 2008, 11:04pm UTC](https://www.ruby-forum.com/t/cookies-path-rewrite/151736/1 "2008-10-24T23:04:57Z")

</div>

Greetings

I’m writing to this list, since I was unable to find solution online.

We are using nginx on our all servers and we are very satisfied.  
Thank you very much for this wonderfull work!

One type of our usage is to serve Tomcat 5.5 applications on specified  
desired domains. For example:

[www.example.com](http://www.example.com) \<–[nginx]–\>  
[http://tomcat-server.platon.sk:8180/AppDir/](http://tomcat-server.platon.sk:8180/AppDir/)

This works great, however we need to use rewrite this way for removing  
/AppDir/ from links, FORM actions and so on:

server {  
listen 80;  
server\_name [www.example.com](http://www.example.com);  
rewrite ^/AppDir/(.\*) /$1;

```
 location / {
         proxy_pass http://tomcat-server.platon.sk:8180/AppDir/;
 }

```

}

This also works great, however when application set up PATH in cookie,  
in example cookie like this is sent:

Set-Cookie: JSESSIONID=4961D9D7519835620F9E6D0622F69ECA; Path=/AppDir

In this case, authentication is not working correctly, because this  
cookie is set for PATH /AppDir and we are on PATH / on server  
[www.example.com](http://www.example.com) (so not tomcat-server.platon.sk anymore).

Any suggestions and ideas would be greatly appreciated.

Thank you

Ondrej

---

<div class="post-metadata">

**Author:** ![Ondrej\_Jombik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a698b9/32.png) [@Ondrej\_Jombik](https://www.ruby-forum.com/u/Ondrej_Jombik)\
**Post date:** [December 31, 2008, 4:48am UTC](https://www.ruby-forum.com/t/cookies-path-rewrite/151736/2 "2008-12-31T04:48:44Z")

</div>

Ondrej Jombik wrote:

> ```
> server_name www.example.com;
> 
> ```
> 
> Set-Cookie: JSESSIONID=4961D9D7519835620F9E6D0622F69ECA; Path=/AppDir
> 
> In this case, authentication is not working correctly, because this  
> cookie is set for PATH /AppDir and we are on PATH / on server  
> [www.example.com](http://www.example.com) (so not tomcat-server.platon.sk anymore).
> 
> Any suggestions and ideas would be greatly appreciated.

This solution worked for me:

> **[Question: Setting SESSION Cookie Paths in Apache Tomcat](https://blogs.starcio.com/2006/11/question-setting-session-cookie-paths.html)**
>
> Topics for CIO CTO CDO and CMO covering Agile, BigData, DevOps, Dat Management, Data Visualization and Digital Transformation

---

<div class="post-metadata">

**Author:** ![Ondrej\_Jombik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a698b9/32.png) [@Ondrej\_Jombik](https://www.ruby-forum.com/u/Ondrej_Jombik)\
**Post date:** [January 4, 2009, 10:48pm UTC](https://www.ruby-forum.com/t/cookies-path-rewrite/151736/3 "2009-01-04T22:48:30Z")

</div>

We used solution, which reset all the cookie paths to simple ‘/’

It can be configured in Tomcat with:

```
 emptySessionPath="true"

```

So whole directive:

```
 <Connector port="8080" protocol="HTTP/1.1"
     connectionTimeout="20000"
     redirectPort="8443"
     emptySessionPath="true" />

```

But I would like to see better solution than this.

Ondrej
