0

We have a multisite CMS that handles images and other files like this..

How can we cache images and other files that are in www.(or non-www.)variable-domain.com/files/* with .htaccess?

This is causing a 500 error. I stripped out some.. here is what I have currently that works (minus the Directory and contents part - it throws the error when thats included).

#
#   Force Browser Cache
#
<ifmodule mod_expires.c>
ExpiresActive On

<filesmatch "\.(jpg|gif|png|css|js)$">
    ExpiresDefault "access plus 1 year"
</filesmatch>

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

<FilesMatch ".(js|css|pdf|txt)$">
    Header set Cache-Control "max-age=604800"
</FilesMatch>

<Directory "/home/aiwebsystems/public_html/uploads">
    <FilesMatch "\.(gif|jpg|png|js|css)$">
        ExpiresDefault "access plus 1 year"
    </FilesMatch>
</Directory>

</ifmodule>

I would need all subdirectories of this included too...

Thanks for the help!

Ryan Thompson
  • 458
  • 5
  • 15
  • 3
    1. Dude, 10 questions with 8 answers and 0 accepted answers? Really :) ? 2. What matters is not whether or not the app is written in CodeIgniter but that you are running an apache web server :) – abcde123483 Nov 08 '11 at 20:21
  • My bad man, Ill go back and accept some answers lol - Im somewhat of a noob here.. – Ryan Thompson Nov 08 '11 at 21:13

3 Answers3

2

Use Apache's mod_expires

e.g in your .htaccess put:

ExpiresActive On

<Directory "/path/to/public_html/files">
    Options FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
    ExpiresDefault A300
    <FilesMatch "\.html$">
        Expires A86400
    </FilesMatch>
    <FilesMatch "\.(gif|jpg|png|js|css)$">
        Expires A2592000
    </FilesMatch>
</Directory>

A300 meaning that the user cached copy expires 300 seconds after access. (A86400 is a day after access, A2592000 is a month after access)

If you mean server side caching, well then you are in luck as the operating system caches recently using a 'paging' algorithm: http://en.wikipedia.org/wiki/Paging

abcde123483
  • 3,885
  • 4
  • 41
  • 41
1

<Directory> is not allowed in htaccess.

Just create a new .htaccess file, with the expires stuff, and put it inside the 'uploads' directory. This will have the same effect you try to achief

Gerben
  • 16,747
  • 6
  • 37
  • 56
0

Being as it does not have an extension, none of this worked. I change the code in the end and it works great now, using the file name rather than the image ID as the last URI parameter.

Ryan Thompson
  • 458
  • 5
  • 15