I can't find a way to do it. Is it even possible?
Asked
Active
Viewed 4,640 times
4 Answers
1
You could create a custom script and redirect all your images to that script. It's kind of a big overhead but it works if it's your only option.
For example
http://yoururl.com/img.php?image=banner.jpg
And that script would contain for example:
<?php
header('Expires: full_date_comes_here');
echo file_get_contents('images/'.$_GET['image']);
?>
Note!!! This is just a dummy example and you should add validation to your script, to prevent attacks using "../" parts etc.
aardbol
- 1,463
- 4
- 17
- 25
0
Windows based hosting with godaddy doesnt support .htaccess, you have to use web.config.
Lucas Kauffman
- 16,818
- 9
- 57
- 92
0
Like this:
<FilesMatch "\.(jpg|png|gif|js|css|ico|swf)$">
Header set Expires "Thu, 31 Dec 2037 23:55:55 GMT"
Header set Cache-Control "public,max-age=315360000"
Header set Vary "Accept-Encoding"
</FilesMatch>
If you want a shorter caching period, remove Header set Expires
and adjust Header set Cache-Control
.
sanmai
- 521
- 5
- 19
0
Yes, mod_expires will work via .htaccess files. Put this in your .htaccess file:
ExpiresActive on
ExpiresByType image/gif "access plus 1 day"
ExpiresByType image/jpeg "access plus 1 day"
ExpiresByType image/png "access plus 1 day"
-
2mod_expires *does not* work in a shared hosting environment. I just tried this and got a 500 error. – Jared Jun 12 '10 at 00:28