Disable Cookies using .htaccess file

  • Avinash
  • 8
  • May 21, 2012
  • Tips & Tricks

Here I comes with the quick tip, this is small tip but very effective. This is about disabling the Cookies on site.

You might be suprised that, Why someone would like to disble the cookies on the website? I would say that is the proper question, but sometimes it would be good to disable the cookies especially for the Cookie Free Domain.

Cookie Free Domain?

Cookie Free Domain is just like simple domain or sub domain which are used to serve the static contents and which have no one cookies are set. So when we have separate domain for the serving the static content the it will increase the performance of the website by loading the content in parallel. But what is the relation with the disabling the cookies? You can find this relation in benefit section of this article.

Disable Cookies using .htaccess

Here are the simple just two lines to disable cookies on domain using Htaccess file.

Header unset Cookie Header unset Set-Cookie
  Header unset Cookie
  Header unset Set-Cookie


When browser makes any request to the server then it will send all cookies in header with all request. So let’s assume if you have 1 KB of cookies set and you are making 100 requests to the server then that 1 KB will sent to server 100 times and server also send that back to browser aswell.

So I hope you are now clear with the concept/relation of the Cookie Free Domain and disabling the cookies with .htaccess file.

If you want to create a cookie free subdomain for wordpress then you will like this article for sure.

So I keep this topic open over here. You can ask questions by comments if you have any.

Also don’t forget to Subscribe to our feed, Like us on Facebook and Follow us on Twiiter to get updates for the new posts/article.

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by:

  • Yuri Taillandier

    Excellent hint ! It saves you from spending extra cash on an additional domain to serve static content.

    Just set up a cdn.yourdomain.com subdomain and put these directives into the htaccess file and voila – you have your own static, cookieless domain.

  • Chris

    Anyone know how to do cookie-free domains on joomla? I been trying to
    test my site with yslow and got suggestion to do that. There is option
    in joomla global configuration – Site Settings – Cookie setting – cookie
    domain and cookie path but I tried a lot of options that I found online
    but I guess I don’t know how to do it properly.

    I created subdomain but the same thing, I copied static elements like
    images to that domain and linked through css but nothing happens.

    after that I tried not to create new folder when I was creating new
    subdomain but link subdomain in same folder where main domain is, but
    nothing happens.

    Any ideas? Thanks

  • hari

    This does not work on magento, do you have any solutions?

    • http://www.xpertdeveloper.com/ Avinash

      This is not specific to any framework or opensource, so basically it shoudl work with magento as well.

      I would suggest you to look if you are making changes to correct .htaccess file.

      • hari

        It does it seem to work

  • make

    I put the above two line in my .htaccess file . my problem is solve but i can’t login in admin panel .

    • http://www.xpertdeveloper.com/ Avinash

      This means, your admin login code is done cookies and you have disabled it.

      Session is suggested to use for maintaining session login. Hope this helps

  • Sohail Rahman Khan

    Hi I have a development domain. I have added this to .htaccess file of that.
    Now I am linking the css file from that domain but still Yslow shows that css file being pulled is not cookie free.
    I have apache 2.2 server, Modx CMS.