Title: Adding custom headers to cached documents
Last modified: September 1, 2016

---

# Adding custom headers to cached documents

 *  Resolved [cybmeta](https://wordpress.org/support/users/cybmeta/)
 * (@cybmeta)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/adding-custom-headers-to-cached-documents/)
 * I would like to add custom headers to files cached by LSCache. I was doing it
   from .htaccess but it no longer works as before. Exactly, I not able to add ETag
   from the .htaccess in the root directory of my WordPress install. I used this
   code before with success.
 *     ```
       AddDefaultCharset UTF-8
       FileETag MTime Size
       <IfModule mod_headers.c>
           Header unset Last-Modified
           Header set Cache-Control "no-cache"
       </IfModule>
       ```
   
 * What I want to get is:
 *  – Server-side caching: LSCache seems to be working but I’m not sure. I can see
   the header x-litespeed-cache
    hit but the **storage directory is empty**.
 *  – Client-side not caching but allow 304 Not Modified responses: I get this with
   Cache-Control “no-cache” and ETags. With these headers, the HTML document is 
   not cached client-side but it is not downloaded in every request if it has not
   been modified due 304 Not modified responses.
 * I think I can not set ETags because MTime requires access to file’s information
   but the file is stored higher in the server directory tree, outside WordPress
   directory and out of the scope of the .htaccess, is it correct?
 * ¿Any suggestion?
 * [https://wordpress.org/plugins/litespeed-cache/](https://wordpress.org/plugins/litespeed-cache/)

Viewing 14 replies - 1 through 14 (of 14 total)

 *  Plugin Author [LiteSpeed Technologies](https://wordpress.org/support/users/litespeedtech/)
 * (@litespeedtech)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/adding-custom-headers-to-cached-documents/#post-7694255)
 * We will look into setting custom headers. It _should_ work.
 * To clarify, you are looking to add the ETag header to files that are served from
   the cache? Or are you looking to add the ETag header to files that are inserted
   into the cache?
 * To provide more information, when a page is cached, the headers are also cached(
   minus set-cookie), so the rules you need may differ depending on what you’re 
   looking for.
 *  Thread Starter [cybmeta](https://wordpress.org/support/users/cybmeta/)
 * (@cybmeta)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/adding-custom-headers-to-cached-documents/#post-7694267)
 * I’m not sure what option is more accurate in the validation of the 304 response,
   but as long as a cached file is valid, it should generates a 304 response, so
   I think that the option of adding ETag to the files served from cache is better.
   I’ve been using it with success for a long time through the .htaccess file of
   the cache storage directory, for example `wp-content/cache/page_enhanced` from
   W3TC.
 *  Plugin Author [LiteSpeed Technologies](https://wordpress.org/support/users/litespeedtech/)
 * (@litespeedtech)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/adding-custom-headers-to-cached-documents/#post-7694277)
 * Currently, the cache does not handle the ETag Header. It will be added to LSWS
   Enterprise 5.1.8.
 * The cache location will not matter.
 * Thanks for bringing this issue up!
    Kevin
 *  Thread Starter [cybmeta](https://wordpress.org/support/users/cybmeta/)
 * (@cybmeta)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/adding-custom-headers-to-cached-documents/#post-7694286)
 * Thanks to you for the consideration.
 * I’m currently testing LSWS with the free 15 day trial.
 *  Thread Starter [cybmeta](https://wordpress.org/support/users/cybmeta/)
 * (@cybmeta)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/adding-custom-headers-to-cached-documents/#post-7694320)
 * Just to be clear; I talked about .htaccess in wp-content/cache/page_enhanced 
   from W3TC, but I’m using LiteSpeed Cache now.
 *  Plugin Author [LiteSpeed Technologies](https://wordpress.org/support/users/litespeedtech/)
 * (@litespeedtech)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/adding-custom-headers-to-cached-documents/#post-7694325)
 * So you will add the rule to the regular wordpress .htaccess, correct?
 *  Thread Starter [cybmeta](https://wordpress.org/support/users/cybmeta/)
 * (@cybmeta)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/adding-custom-headers-to-cached-documents/#post-7694329)
 * I tried to add it in the regular WordPress .htaccess using the code above, which
   is what I was using previously within W3TC cache storage directory, but with 
   LiteSpeed only Cache-Control is added.
 * Anyway, there is a problem by adding ETags in the regular WordPress .htaccess.
   I think it would be better if ETags are handle by LiteSpeed Cache module and 
   not in the regular WordPress .htaccess.
 * Why?
 * Although I couuld accept adding ETags to all responses, I’m sure many people 
   would want to add ETags only to certain documents types, and that is not always
   posible in the WordPress root directory. At least I’ve not found a way to do 
   it.
 * For example, if you use this permalink structure for a post: `example.com/some-
   post`, it returns a HTML document but without a html file extension, so you can
   not use `FileMatch`. You can not check mime types neither at this moment, as 
   it requires the response and we are earlier.
 * There can be also a URL that returns a XML document, for example `example.com/
   comments/feed`.
 * In this context, using the root .htaccess you could not add ETags only to HTML
   documents if you want. At least, again, I’ve not found how to do it.
 * In other cache plugins using disk for cache storage, this can be solved by using
   the .htaccess in the storage directory.
 * That is why I think if you shold be handle by LiteSpeed Cache module. I hope 
   it makes sense.
 *  Plugin Author [LiteSpeed Technologies](https://wordpress.org/support/users/litespeedtech/)
 * (@litespeedtech)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/adding-custom-headers-to-cached-documents/#post-7694331)
 * Understood. Thanks for the clarification. Will get back to you on this.
 * For what it’s worth, it may be a bit tricky because we do not redirect the request
   to the cache root. The original path (post rewrites) is used to create the cache
   entry. Either way, I will get back to you when I have a solid answer.
 * Kevin
 *  Thread Starter [cybmeta](https://wordpress.org/support/users/cybmeta/)
 * (@cybmeta)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/adding-custom-headers-to-cached-documents/#post-7694332)
 * Ok, thank you.
 * Anyway, adding support for ETags in .htaccess would be great also. Don’t forget
   that.
 *  Plugin Author [LiteSpeed Technologies](https://wordpress.org/support/users/litespeedtech/)
 * (@litespeedtech)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/adding-custom-headers-to-cached-documents/#post-7694334)
 * I have clarification from both sides 🙂
 * So the FileETag rule you listed above _does_ work in Enterprise already. However,
   as I mentioned before, our cache entries aren’t actual files, so that rule did
   not work for the requests served from cache.
 * That said, the thing I mentioned earlier that will be added in 5.1.8 – we will
   add an option to our configurations that enable admins to select “add ETags to
   cache entries”. That should take care of your original issue, I think.
 * Let me know if this answers your questions!
    Kevin
 *  Thread Starter [cybmeta](https://wordpress.org/support/users/cybmeta/)
 * (@cybmeta)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/adding-custom-headers-to-cached-documents/#post-7694335)
 * `Yes, it does. Everything is perfectly clear.
 * Thank you!!
 *  Plugin Author [LiteSpeed Technologies](https://wordpress.org/support/users/litespeedtech/)
 * (@litespeedtech)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/adding-custom-headers-to-cached-documents/#post-8203923)
 * Hi Cybmeta,
 * We released 5.1.8 last week. It should have included the ETag support. Let us
   know if you encounter any problems!
 *  Thread Starter [cybmeta](https://wordpress.org/support/users/cybmeta/)
 * (@cybmeta)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/adding-custom-headers-to-cached-documents/#post-8209924)
 * Tested and working. Thank you!!
 *  Plugin Author [LiteSpeed Technologies](https://wordpress.org/support/users/litespeedtech/)
 * (@litespeedtech)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/adding-custom-headers-to-cached-documents/#post-8210079)
 * Good to hear!
 * Cheers,
    Kevin

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘Adding custom headers to cached documents’ is closed to new replies.

 * ![](https://ps.w.org/litespeed-cache/assets/icon-256x256.png?rev=2554181)
 * [LiteSpeed Cache](https://wordpress.org/plugins/litespeed-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/litespeed-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/litespeed-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/litespeed-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/litespeed-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/litespeed-cache/reviews/)

 * 14 replies
 * 2 participants
 * Last reply from: [LiteSpeed Technologies](https://wordpress.org/support/users/litespeedtech/)
 * Last activity: [9 years, 8 months ago](https://wordpress.org/support/topic/adding-custom-headers-to-cached-documents/#post-8210079)
 * Status: resolved