The website I'm working on has 5 domains (two top level and 3 subs, not including www). I need to limit the cookie that the site creates to only work on 4 of the domains.

I have found from here that in Drupal 8 cookies are defined in the services.yml file using this:

    cookie_domain: '.domain.com'

But I'm unsure how I can add multiple domains. Is it as simple as something like this?

cookie_domain: 'www.domain1.com'; 'domain1.com'; 'sub1.domain.com'; 'sub2.domain.com'

1 Answer 1


A cookie can only have 1 domain value. So you can either set it to a specific domain or the top domain wich includes all the subdomains.

See https://stackoverflow.com/questions/1062963/how-do-browser-cookie-domains-work

  • 1
    That doesn't really answer the question and your answer is contradictory. If I set it to the top level domain then more than 1 domain can be used i.e a global cookie. How do I limit it to only specific sub domains?
    – Krypton
    May 28, 2017 at 11:08
  • 1
    Further more, drupal handles assigning cookies for both my top level domains without this setting, how would I replicate this if I were to use the cookie_domain value so cookies won't work on sub domains?
    – Krypton
    May 28, 2017 at 11:19
  • 1
    The answer seems clear, to me: Or you set cookie_domain to .example.com, which means all the sub-domains of example.com (including example.com), or you set it to sub.example.com, or example.com, which makes the cookie just for a domain.
    – apaderno
    May 28, 2017 at 16:40
  • 1
    I know how cookies work but this isn't a cookie issue it's a dynamic drupal issue. Multi domain cookies could be used in earlier versions of drupal drupal.org/node/1348784 how do I do this in Drupal 8???
    – Krypton
    May 29, 2017 at 4:57
  • 1
    Without having the cookie_domain set, both of my top level domains handle logins fine, how would I replicate this setting? If I can only input one domain then the other will stop working. Also I apologies if I'm appearing blunt, I do appreciate any help :)
    – Krypton
    May 29, 2017 at 5:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.