Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding ExpiresDefault to .htaccess file

I have updated my .htaccess file to include the following:

<FilesMatch "\.(css|js)$">
ExpiresDefault "access plus 1 month"
</FilesMatch>

I am trying to tell the client that all css and js wont change for 1 month so they can cache they files.

I have 2 questions,

  1. Is this going to achieve what I want
  2. Since adding that I am now getting a 500 error, the whole .htaccess file is below:

    
    <FilesMatch "*\.(css|js)$">
    ExpiresDefault "access plus 1 month"
    </FilesMatch>
    # BEGIN Compression (DEFLATE)
    <IfModule mod_deflate.c>
    # Enable compression
    AddOutputFilterByType DEFLATE text/css text/javascript application/x-javascript text/html ``text/plain text/xml image/x-icon
    <IfModule mod_setenvif.c>
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
    </IfModule>
    <IfModule mod_headers.c>
    # Make sure proxies deliver correct content
    Header append Vary User-Agent env=!dont-vary
    # Ensure proxies deliver compressed content correctly
    Header append Vary Accept-Encoding
    </IfModule>
    </IfModule>
    # END Compression (DEFLATE)

like image 326
Aly Avatar asked Mar 12 '11 18:03

Aly


People also ask

How to Add Expires Headers html?

Expires Headers are certain lines of code that tell your browser how long it should keep the cached files from your site. You can add Expires Headers by adding a code such as ExpiresByType image/jpg “access plus 1 month” to your site.

How do I add expired headers to my website?

Place all of the resources (such as images, scripts, etc.) that you would like to set far-future expirations for into the static folder and then add an . htaccess file to that folder that includes the expires headers. Place the rest of the resources that you do not want cached into the other folder .

What are Expires Headers?

The expires header is an HTTP header that indicates whether it is possible to obtain information on request from the browser cache or if you need to access the server since the page option in the cache is already outdated. This header contains the date and time until the page is available in the browser cache.


1 Answers

Make sure ExpiresActive ON is set inside of your FilesMatch directive before ExpiresDefault.

like image 182
Butifarra Avatar answered Sep 26 '22 18:09

Butifarra