How do I setup expire headers in Apache?

Linode Staff

I would like to speed up my site by having the client's browser cache images and other content.

I am currently including the following in my configuration:

<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
</IfModule>

..but my web server is apparently not sending the correct headers. How can I fix this?

1 Reply

This answer assumes that you are using Apache 2.4.

The documentation for this feature can be found here:

The first thing you would want to check is to see that the mod_expires.c module is enabled. You can do this with the following command:

sudo a2enmod expires

You may then want to restart your web server to ensure that the configurations take effect:

sudo systemctl restart apache2.service

If you are using .htaccess files, you will need to make sure that they are enabled as well:

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct