Question

How to setup expire headers on Apache?

Hi!

I used like 3 different WP plugins but none of them worked so far… so I guess I’ll have to do it manually on my server

I haven’t found any tutorial though so that’s why I’m asking you where and how can I setup expire headers for css, png, jpg,… basically everything (as long as it’s useful)

Thanks :)

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Try something like this (note: this needs the mod_expires module. Enable it with “a2enmod expires” if you’re using Ubuntu or Debian - afterwards restart Apache):

    ExpiresActive on
    ExpiresDefault "access plus 30 seconds"
    ExpiresByType text/html "access plus 15 days"
    ExpiresByType image/gif "access plus 1 months"
    ExpiresByType image/jpg "access plus 1 months"
    ExpiresByType image/jpeg "access plus 1 months"
    ExpiresByType image/png "access plus 1 months"
    ExpiresByType text/js "access plus 1 months"
    ExpiresByType text/javascript "access plus 1 months"
</IfModule>```

I hope it works for you :). Please let me know if it works!

Thanks works like charm !!!

The issue is resolved (I don’t have httpd.conf but apache2.conf!) it just didn’t have the right permission…

Thank you!

Ok so I tried many times but it still doesn’t work:

When I add the mod expires lines I get a 500 error but if I remove it everything works fine…

I did sudo a2enmod expires and sudo a2enmod header and they are both enabled…

Any explanation? I’ve head it can be something wrong in my httpd.conf but I don’t have that file.

Thank you :)

Before doing anything, can you confirm that I have to put these lines in .htaccess and not in a VirtualHost configuration?