Forum Moderators: phranque

Message Too Old, No Replies

Image Caching With .htaccess

         

imbckagn

1:05 am on May 12, 2010 (gmt 0)

10+ Year Member



I am trying to set image caching through .htaccess but I can't seem to get it to work. I'm totally clues when it comes to servers but I just moved to a dedicated server at Hostgator. The code below is what I'm adding to my .htaccess file for a WordPress website which doesn't work.

<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>

Any help would be appreciated.

jdMorgan

2:31 am on May 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could be/should be:

<FilesMatch "\.(flv|gif|jpe?g|png|ico|swf)$">
Header set Cache-Control: "max-age=2592000"
</FilesMatch>

But please define "doesn't work." Otherwise, the only available diagnosis will be "because it's broken."

How did you test?
What did you expect?
What were the actual results?
How did the results differ from your expectations?

Extra points for relevant supporting server access log and "Live HTTP Headers" logs.

Jim

imbckagn

3:52 am on May 12, 2010 (gmt 0)

10+ Year Member



Thanks Jim that "worked" :)

What I meant by doesn't work was the code was not enabling caching of the files at all. I am using firebug and page speed for FireFox to analyze a website.

Thanks

jdMorgan

1:26 pm on May 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, your code wasn't "optimal" but it should have functioned almost correctly.

Do be sure to completely delete your browser cache before testing any changes to any kind of server-side code. Otherwise, you're likely to get confusing test results due to your browser showing you previously-cached objects and server responses.

Jim