setting up a cookie less sub domain

14,943

Solution 1

Being cookie-less and served by CDN are unrelated properties of a domain.

To make some domain cookie-less for your site you simply should not set cookies visible on that domain and make sure any other third party code you use on your site does not do so.

It is generally inconvinient to avoid cookies from example.com to not not be visible on sub-domains (often sites are served from 2 locations www.example.com and example.com). If you are fine to having cookies on just example.com - make sure that all set-cookie headers specify exact domain ("example.com" not ".example.com") so cookies will not be visible on any subdomain. Another option is to move main site to subdomain and set cookies there (i.e. www.example.com), than again cookies will not "leak" to sibling sub-domains (i.e. "img.example.com")

It may be better idea to host static content on totally separate domain name - easier to controll cookies and potentially more posibilities for CDN (i.e. in some cases HTTPS traffic from CDN may require different actions for custom and CDN-provided domain).

Solution 2

The browser will look at example.com and www.example.com differently. If you set cookies on example.com then it will look for them on requests to www.example.com and cookie-free.example.com which I expect is why you're having trouble getting a cookie free subdomain (because the top level has cookies). Best practice is to use www.example.com as your site, and set cookies there, then if you use cookie-free.example.com (another subdomain, like www) it will not have the cookies which are looked for top down by browsers.

See http://developer.yahoo.com/performance/rules.html#cookie_free for more info.

Share:
14,943
Anik Chakraborty
Author by

Anik Chakraborty

Updated on June 04, 2022

Comments

  • Anik Chakraborty
    Anik Chakraborty almost 2 years

    previously I served images for my site (http://example.com) from these two folders : http://example.com/images and http://example.com/pics

    Now I have created a sub domain img.examole.com and moved those folders to http://img.example.com/pics and http://img.example.com/images locations. I have also blocked access to http://example.com/img folder by editing .htaccess file so that the sub-domain can not be accessed as a directory of main site. It only can be accessed as http://img.example.com

    How can I make this http://img.example.com subdomain a cookie less sub-domain? Or can I add this http://img.example.com sub-domain to cloudflare? I do not want to add the main domain http://example.com to cloud flare. When I am trying to add http://example.com to cloud flare from my CPanel it is showing :

    A type records cannot be directly routed though the CloudFlare network. Instead, click here and either switch the type of img.example.com. to CNAME

    I have changed the image location to http://img.example.com/pics in all my articles. How to fix this? plz help..

  • Anik Chakraborty
    Anik Chakraborty over 11 years
    hi, there is no 'COOKIE_DOMAIN' entry in my wp-config.php file
  • Alexei Levenkov
    Alexei Levenkov over 11 years
    @AnikChakraborty, I did not realized that you have some php specfic question... Unfortunately I have no idea how cookies are configured in php.