On my forum, I have since followed this suggestion to disallow "sid=" in URLs for guests:
To be unconditional:
Now, every time a page is generated for a guest or bot, it will have no sid links and can be cached. These changes will increase the cache hit rate significantly, visible in 'varnishstat' and in lower CPU usage.
This may also reduce load for crawlers that attempt to hit each 'sid=' link separately because sid will no longer be in the links, so the crawlers may make fewer attempts to retrieve pages in the first place.
For those willing to make this kind of change (above) to the forum code, it's appropriate to adjust the default.vcl file. Now that sid isn't being added to the links, it is appropriate to cache the guest HTML output even if it is attempting to set a cookie (because that no longer signals that the page is poisoned with sid links). It is a simple change that involves changing the conditional here:The second change is in append_sid (the root cause of it all) in functions.php.Code:
// Append session id and parameters (even if they are empty)// If parameters are empty, the developer can still append his/her parameters without caring about the delimiter global $user; if ($session_id && $user->data['is_registered']) { return $url . (($append_url) ? $url_delim . $append_url . $amp_delim : $url_delim) . $params . ((!$session_id) ? '' : $amp_delim . 'sid=' . $session_id) . $anchor; } else { return $url . (($append_url) ? $url_delim . $append_url . $amp_delim : $url_delim) . $params . $anchor; }
Code:
if (bereq.http.Varnish-Cache == "1" || bereq.http.Varnish-Cache == "2") { if (bereq.http.Varnish-Cache == "2") { unset beresp.http.Set-Cookie; }
Code:
if (bereq.http.Varnish-Cache == "1" || bereq.http.Varnish-Cache == "2") { unset beresp.http.Set-Cookie;
This may also reduce load for crawlers that attempt to hit each 'sid=' link separately because sid will no longer be in the links, so the crawlers may make fewer attempts to retrieve pages in the first place.
Statistics: Posted by webdev42 — Tue May 06, 2025 2:26 am