I need to get mod_cache_disk to cache a site containing query strings. The issue is that it's a vendor product on IIS that we're trying to cache through mod_proxy and it does not contain expires headers. I realize this issue violates several RFCs and that's why apache does not do it by default.

Is there a way to force apache 2.4.x to cache with query string and no expires header?

This configuration will cache, but of course without honoring ? it caches the wrong content for most items.

CacheEnable disk https://
CacheEnable disk /
CacheRoot /var/cache/mod_proxy/
CacheDirLevels 4
CacheDirLength 5
CacheIgnoreCacheControl On
CacheIgnoreNoLastMod On
CacheIgnoreHeaders None
CacheMaxFileSize 100000000
CacheMinFileSize 1
CacheMaxExpire 1209600
CacheDefaultExpire 3600
CacheIgnoreQueryString On
CacheStoreNoStore On
CacheStorePrivate On

If I change CacheIgnoreQueryString to Off it will start emitting errors about the expires header.

AH00768: cache: /view.image?Id=1114 not cached. Reason: Query string present but no explicit expiration time,


According to this answer the only way to do this is to let Apache see the headers it wants (Expires, which you stated, and, apparently also Last-Modified).

The poster of that answer suggested writing a filter on the application side, but since yours is a vendor product, that may not be possible. Is there a chance to add it directly in IIS? Otherwise, you might have luck with a double proxy setup: use one proxy to add the headers (but not cache), and proxy that from Apache (taking the headers and caching).


that's my solution

<IfModule mod_cache.c>
    CacheIgnoreNoLastMod On
    CacheIgnoreHeaders Set-Cookie
    <IfModule mod_disk_cache.c>
        CacheRoot D:\\apache_cache
        CacheEnable disk /
        CacheDirLevels 1
        CacheDirLength 1

and from the backend side add header


s-maxage - for proxy caches and CDNs


The most obvious solution would be to strip the query string off before it reaches mod_cache.

And the most obvious module for that would be mod_rewrite.

But that won't work, because mod_cache started using purposefully the unchanged version of the query-string in 2006.

  • 1
    How is this the "most obvious" solution, if it won't work? Jun 10 '16 at 23:07

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.