Expires Header

Jim,

In my HTAccess file I have

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

If I wanted an expires header to get people’s browsers to cash my images (located at mysite.com/myimages), can I just add these two lines (for apache 2.2) anywhere between the open and close ifModule lines;

ExpiresByType image/gif "access plus 2 years"
ExpiresByType image/jpeg "access plus 2 years" ?

Thank Jim,

Roger

Comments

  1. AMPC says:

    You can’t force someone’s browser to save your image for a set amount of time, you can only suggest that the browser check every so often for the file.

    For example, my browser clears it’s cache when I shut it down, so you may have two years, but my browsers going to ask for it next time I visit.

    The ExpiresByType command you mention would go in the httpd.conf file, not the .htaccess. See: websiteoptimization.com/speed/tweak/cache/

    Regards,

    Jim.

  2. Actual says:

    Jim,

    The computer’s cache would empty the cache at turn off, but the browser cache may work differently, it may store it’s cache on the hard drive. The reasoning you have suggests that Expires is all but useless. What do you think ?

    Roger

  3. Actual says:

    Jim,
    On the Firefox web browser, for example, choose tools, options, cache, and you

  4. Actual says:

    Jim,

    I decided not to use expires header. Instead I’ll use

    <IfModule mod_headers.c>
    <FilesMatch ".(ico|jpg|jpeg|gif)$">
    Header set Cache-Control "max-age=37440000"
    </FilesMatch>
    <FilesMatch ".(css)$">
    Header set Cache-Control "max-age=87000"
    </FilesMatch>
    <FilesMatch ".(html|htm)$">
    Header set Cache-Control "max-age=300"
    </FilesMatch>
    </IfModule>

    Why don’t I see this reflected in the header for my site, or is it there’s nothing to see?
    seochat.com/seo-tools/check-server-headers/

    Roger

  5. AMPC says:

    Hi Roger,

    What file did you put these commands into?

    When you say they don’t show up, you mean when you view source or when another site does a report?

    Regards,

    Jim.

  6. Actual says:

    Jim,
    On this sk apache page
    askapache.com/htaccess/caching-tutorial-for-webmasters.html
    It says
    * .htaccess files allow web publishers to use commands normally only found in configuration files. They affect the content of the directory they

  7. Actual says:

    Jim,

    This page askapache.com/htaccess/apache-speed-cache-control.html says

    Add Cache-Control Headers
    This goes in your root .htaccess file but if you have access to httpd.conf that is better.

    This code uses the FilesMatch directive and the Header directive to add Cache-Control Headers to certain files.

    # 480 weeks
    <FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$" >
    Header set Cache-Control "max-age=290304000, public"
    </FilesMatch>

    # 2 DAYS
    <FilesMatch ".(xml|txt)$">
    Header set Cache-Control "max-age=172800, public, must-revalidate"
    </FilesMatch>

    # 2 HOURS
    <FilesMatch ".(html|htm)$">
    Header set Cache-Control "max-age=7200, must-revalidate"
    </FilesMatch>

    Roger

Speak Your Mind

Comment moderation is enabled. Your comment may take some time to appear.