Forum Moderators: phranque

Message Too Old, No Replies

mod_expires syntax

         

keyplyr

8:01 am on Nov 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




Continued from this thread [webmasterworld.com]

On stable developed sites, I use 6 to 12 hours for robots.txt, pages, and scripts, 30 days for images, and 0 seconds for custom error pages. - jdMorgan

Are they to be written out individually, or can they be combined?

ExpiresActive On
ExpiresByType image/gif "access plus 30 days"
ExpiresByType image/jpg "access plus 30 days"
ExpiresByType text/html "access plus 6 hours"
ExpiresByType text/txt "access plus 6 hours"
ExpiresByType text/php "access plus 6 hours"
ExpiresByType text/js "access plus 6 hours"
ExpiresByType text/pl "access plus 6 hours"
ExpiresByType error.html "now"
ExpiresByType forbidden.html "now"

jdMorgan

2:11 pm on Nov 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can't combine MIME-types in ExpiresByType, but here's another way to do it - see embedded comments:

ExpiresActive On
# Set default expiry to six hours after last access
ExpiresDefault A21600
# Set expiry for image files to 30 days
ExpiresByType image/gif A2592000
ExpiresByType image/jpg "access plus 30 days"
# Set expiry for error pages to zero
<FilesMatch "^(error¦forbidden)\.html$">
ExpiresDefault A0
</FilesMatch>

Jim

keyplyr

7:03 pm on Nov 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I saw the examples of keeping time relative to seconds at Apache mod_expires [httpd.apache.org] but though it would be more "editor friendly" to spell them out in hours/days/etc. Maybe I will just keep a "seconds" conversion list handy.

So you're saying that this is about as succinct as I can get it then?


ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/jpg A2592000
ExpiresByType text/html A21600
ExpiresByType text/txt A21600
ExpiresByType text/php A21600
ExpiresByType text/js A21600
<FilesMatch "^(error¦authentication¦forbidden)\.html$">
ExpiresDefault A0
</FilesMatch>

Thanks

<added>
what "type" would pdf, wav and mid files be?
</added>

jdMorgan

10:29 pm on Nov 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code I posted above should work, if you add your authentication page name page to it. The first ExpiresDefault directive covers all types not explicitly changed by later directives.

Do a search for "MIME types" for the proper "names" for those other file types.

Jim

keyplyr

11:29 pm on Nov 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



OK - so in this code:

ExpiresActive On
ExpiresDefault A21600
ExpiresByType image/gif A2592000
ExpiresByType image/jpg "access plus 30 days"
<FilesMatch "^(error¦forbidden¦authentication)\.html$">
ExpiresDefault A0
</FilesMatch>

ExpiresDefault A21600

covers html,txt,js,pl, etc

But why the two different time syntaxes?


ExpiresByType image/gif [b]A2592000[/b]
ExpiresByType image/jpg [b]"access plus 30 days"[/b]

Why not make them both the same (since they are)?

ExpiresByType image/gif [b]A2592000[/b]
ExpiresByType image/jpg [b]A2592000[/b]

Thanks

<added>

Actually, testing with the SearchEnginesWorld Server Header Checker [searchengineworld.com] shows everything expiring as indicated except .jpg files, which are defaulting to the 6 hour limit. This is true using A2592000 or "access plus 30 days"

It seems these MIME type names were established before JPEG diversed into the abbreviated "JPG."

So this now fixes it:


ExpiresByType image/jpeg A2592000

</added>

jdMorgan

3:58 pm on Nov 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> But why the two different time syntaxes?

To show that I had no specific preference for the formats, mostly.

Well-spotted on the image/jpeg MIME-type problem! This clearly shows the value of always testing your code before deploying it!

Jim