Forum Moderators: phranque

Message Too Old, No Replies

cache-control giving me a 500 error

         

cgcody

4:13 am on Sep 15, 2006 (gmt 0)

10+ Year Member



Hi WW folks.
First off, as you can see, I'm new here. I'm mainly a web dev hobbyist. I've taken a large interest in xhtml, flash(action script) And (recently) PHP. Seems every time I do a search related to web development, this site comes up, so I thought I'd check it out. What better way to kick it off, than with a question, hey?

Anyway, can anyone tell me why in the world this is giving me a 500 error?

#### Code snip. The rest is below.

<Files about.html contact.html plugs.html>
Header unset Cache-Control
Header append Cache-Control "max-age=2592000"
</Files>

The problem is with having the list of files in the the Files directive tag. If I get rid of all but one (<Files about.html>), it works fine. To my knowledge, this is the correct way of listing multiple files.

And can anyone tell me if this looks good? Anything I should add? I've been trying to wrap my brain around this cache control stuff for a while, but I still feel a bit iffy on the subject.

#### cache control ####

#Default html cache
<FilesMatch \.html$>
Header append Cache-Control "max-age=86400"
</FilesMatch>

# Cache for pages that don't get updated often
<Files about.html contact.html plugs.html>
Header unset Cache-Control
Header append Cache-Control "max-age=2592000"
</Files>

#.css and images. I'll combine these 2 when I can figure out the above problem
<FilesMatch \.css$>
Header append Cache-Control "max-age=2592000"
</FilesMatch>

<FilesMatch \.(gif¦jpg¦jpeg¦bmp)>
Header append Cache-Control "max-age=2592000"
</FilesMatch>

#### / cache control ####

Thanks. :)

jdMorgan

1:10 pm on Sep 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



cgcody,

Welcome to WebmasterWorld!

> To my knowledge, this is the correct way of listing multiple files.

The reason you're having problems is that the basic <Files [httpd.apache.org]> directive does not support multiple files at all.

However, you may use the special extended regular-expressions version of <Files>, or use the <FilesMatch> directive to accomplish your goal using the "OR" function of regular expressions.


<Files> ~ "(about¦contact¦plugs)\.html$"
-or-
<FilesMatch> "(about¦contact¦plugs)\.html$"

Note: Change the broken pipe "¦" characters in the code above to solid pipe characters before use; Posting on this forum modifies the pipe characters.

Jim

coopster

1:14 pm on Sep 15, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, cgcody.

Let's start with that <Files> [httpd.apache.org] container. One file, not a list. To incorporate a list of files you need to use regular expression matching.

<added>
Too slow this morning ;)
Thanks jd --
</added>

cgcody

6:54 pm on Sep 15, 2006 (gmt 0)

10+ Year Member



Ahh, I see. Thank you both.

I guess I was thrown off by the directive being called <File(s)>. Odd that it was made plural.

The link you gave me says <FilesMatch> is preferred, so I'll go with that method.

Thanks again.

jdMorgan

7:37 pm on Sep 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is <Files> because any files of that name, in this directory or any directory below it, will be affected by the directives within that <Files> container.

The code

 <Files foo.bar>
Deny from all
</Files>

placed in the top-level .htaccess file would disallow access to /foo.bar, /quux/foo.bar, and /razz/quux/foo.bar, etc.

Jim

cgcody

9:21 pm on Sep 15, 2006 (gmt 0)

10+ Year Member



Ok, that makes sense. Thanks.