Add Expires Header

As per recommendation of GTMetrix, I added the following code into .htaccess but it has no effect at all.

 <ifmodule mod_expires.c=""># Enable expirations
ExpiresActive On 
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"</ifmodule> 

I tried inserting the above code into /etc/apache2/apache2.conf, but no luck. :roll:

Somebody help me please.

3 Replies

Do you have the module expires enabled?

I dont know how to enable it.

I got it. :D

after executing the following command.

sudo a2enmod expires

Thanks for the help.

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