How to Delete Cookie in Apache

delete cookie in apache

Cookies are a great way to provide personalized user experience. However, when they behave or cause issues, then it might be a good idea to simply delete them. Let us take a look at how to delete cookie in Apache.


How to Delete Cookie in Apache

Here are the steps to delete cookie in Apache. We will use mod_headers to manipulate cookies.

Please ensure you have enabled mod_headers in Apache for this purpose. Here are the steps.


1. Open Apache Config file

Open Apache config file in a text editor. You will find it at one of the following locations, depending on the type of installation and your linux distribution.

  • /etc/apache2/httpd.conf
  • /etc/httpd/httpd.conf
  • /etc/httpd/conf/httpd.conf


$ sudo vim /etc/apache2/httpd.conf


2. Delete Cookie

There are multiple ways to delete cookie in Apache.


If you want to delete all cookies on your server, add the following line to your Apache config file.

RequestHeader unset Cookie


If you want to delete any specific cookie,

'Header add Set-Cookie "ANY_COOKIE='';expires='SOME_DATE_IN_PAST'; Max-Age=0; Path=COOKIE_PATH"'




'RequestHeader add Cookie "ANY_COOKIE='';expires='SOME_PAST_DATE'; Path=COOKIE_PATH"'


If you want your server to stop passing cookies back to the client,

Header unset Set-Cookie


3. Restart Apache web server

Restart Apache web server to apply changes

$ sudo /etc/init.d/apache2 start [Debian or Ubuntu]
# sudo apachectl restart [RHEL, CentOS or Fedora]


That’s it! Now Apache will automatically delete existing cookies. If you want to re-enable cookies, just remove the above code and restart server.



About Sreeram Sreenivasan

Sreeram Sreenivasan is the Founder of Ubiq, a business dashboard & reporting platform for small & medium businesses. Ubiq makes it easy to build business dashboards & reports for your business. Try it for free today!