# Add header Expires and Cache-Control when response is 404

**URL:** <https://www.ruby-forum.com/t/add-header-expires-and-cache-control-when-response-is-404/202954>\
**Category:** NGINX\
**Created:** [February 9, 2011, 3:20pm UTC](https://www.ruby-forum.com/t/add-header-expires-and-cache-control-when-response-is-404/202954 "2011-02-09T15:20:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [February 9, 2011, 3:20pm UTC](https://www.ruby-forum.com/t/add-header-expires-and-cache-control-when-response-is-404/202954/1 "2011-02-09T15:20:38Z")

</div>

Hello,  
I need to add header Expires, when the response code is 404.  
Unfortunately HttpHeadersModule can set the header just when the  
response is 200, 204, 301, 302 or 304. It’s no problem to add the header  
using HttpHeadersMoreModule even if the status is 404. But It is written  
in description of HeadersMoreModule:  
“Unlike the standard headers module, this module does not automatically  
take care of the constraint among the Expires, Cache-Control, and  
Last-Modified headers. You have to get them right yourself or use the  
headers module together with this module.”  
How can it be done using both modules together? Or another idea? Or, how  
can I get time that would represent: now + 24h and then add this value  
to the header using more\_set\_headers directive?  
more\_set\_headers ‘Expires: $time\_now\_plus\_24h’

Thank in advance,  
Michal

Posted at Nginx Forum:

> **[add header Expires and Cache-Control when response is 404](https://forum.nginx.org/read.php?2,173527,173527#msg-173527)**
>
> Hello, I need to add header Expires, when the response code is 404. Unfortunately HttpHeadersModule can set the header just when the response is 200, 204, 301, 302 or 304. It's no problem to add the header using HttpHeadersMoreModule even if the...
