0

I have a multisite with each blog on a subdomain. I plan to create another site (let's say blog92.example.com) which I will tell the main site to serve images from - pretty much as per this question.

That seems fairly simple. However, I want just that one blog (blog92.example.com) to never, ever, set cookies. This is because images do not need cookies; so why waste bandwidth on them?

How do I do prevent one specific blog from ever setting cookies while leaving the others unaffected?

1

I read the other question to better understand what you intend on doing. The first thing you need to understand is that there are many ways cookies can be sent and without knowing any details of your hosting environment, of what you have control over, it is impossible to state, specifically, what you need to do. So, that said, here are some things you can start with.

Cookies are part of the HTTP specification. Assuming your server is Apache, you may need to either disable some Apache modules that send cookies by default, or modify their corresponding configuration files to tell them not to send cookies at all. The exact method for doing this can probably be found at the links above (but again, without knowing what platform you are on, this information could be completely wrong). Nginx is another, popular, HTTP server. If you are using nginx, then you'll need to explore which nginx directives are possibly sending cookies and make sure they are disabled in the nginx configuration file.

PHP is able to interact with the HTTP headers and thus, can insert cookies. Normally, when serving only images, you aren't interacting with PHP, so, although this shouldn't affect you, I'm including it for sake of completeness.

By default, PHP might be configured to send a session cookie. To disable this feature, you'll need to disable automatic sessions in PHP for the domain serving the images. See https://www.php.net/manual/en/configuration.changes.php for details on how to change this setting (it can be set in .htaccess or in httpd.conf or equivalent - if you're on nginx, you are probably also using PHP-FPM and runtime configuration settings can probably be set in the corresponding php-fpm.domain.conf file, but you'll need to look up the exact method yourself as the configuration can vary quite a bit).

If you serve JavaScript from this domain you need to make sure you are not including libraries from other domains inside your JavaScript. Likewise with CSS as these other domains may send their own cookies as part of each request.

In the end, you really should be using Cloudflare or some other CDN that can be configured more easily to not send cookies for static resources such as images. Additionally, a CDN will serve these assets from a location that is closer to your end users and thus, reduce the time required to load the images.

If you are serving images from a site on a multisite and the URL is directly to the images (ends in .jpg or similar) then WordPress is not a factor in the equation (because PHP is not triggered and thus does not send session cookies). If you look at the rewrite rules in .htaccess, you'll notice that they state: if the file exists on the server, then serve the file directly.

Said another way, you are using WordPress to upload the images, but not to serve them. Serving them is done by Apache (under normal circumstances), so if cookies are being sent, you have to disable them in Apache, not WordPress and not PHP.

  • This answer is a great guide to cookie control in general. In my case, I am expressly interested in WordPress not setting any cookies from one site in a multisite configuration where the other sites most certainly must send cookies (logins etc.). Nice answer - good resource too - just not to/for my rather specific question. – Matthew Brown aka Lord Matt Sep 4 '19 at 19:57
  • 1
    Thanks. I've updated my answer. Added two paragraphs at the end. You've asked a big question so it is a lot to consume but I am confident I've answered the question. If you have specific follow up questions, please create a new question and reference this one, and provide concrete details and code examples and I'm sure you'll be happy with the answers. – Ted Stresen-Reuter Sep 5 '19 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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