Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove a cookie in Apache

I need to remove a cookie from the HTTP request that gets to the server. Doing it on the client (that writes this cookie) or on the server (that reads it) is not an option. I have Apache 2.0 that proxies requests between client and the server, so I was hoping to remove the cookie right there in Apache using mod_rewrite.

My question is, is there a way to remove a certain cookie from the HTTP request using mod_rewrite?

If not possible to remove just one cookie then as a last resort to remove all cookies from the request?

I am open to other suggestions of how to accomplish this if mod_rewrite is not the right tool for this task.

like image 216
Sergey Golovchenko Avatar asked Nov 25 '09 17:11

Sergey Golovchenko


2 Answers

Apache mod_rewrite allows manipulation of URLs but not of HTTP headers, however 'mod_headers' will let you do that.

So, you could use:

RequestHeader unset Cookie

This will strip all cookies from the request. I'm not sure if its possible to remove just a particular cookie using this technique.

Alternatively, you can stop cookies being passed back to the client using:

Header unset Set-Cookie

if that's more appropriate.

like image 179
Andy Avatar answered Sep 18 '22 07:09

Andy


With Apache > 2.2.4, you could have used :

RequestHeader edit Cookie "^(.*?)ANY_COOKIE=.*?;(.*)$" $1$2
like image 38
Anthony O. Avatar answered Sep 21 '22 07:09

Anthony O.