Your Webmaster Resources Your Webmaster Resources Search Your Webmaster Resources

Yourwebmasterresources Black Fr Font%3E%3C A%3E%3C Font%3E%3C Span%3E%3C P%3E%3Ca%20href Your Webmaster Resources cache control in htaccess Apache Web Server forum at WebmasterWorld

Yourwebmasterresources Black Fr Font%3E%3C A%3E%3C Font%3E%3C Span%3E%3C P%3E%3Ca%20href Your Webmaster Resources

Font%3E%3C t Font%3E%3C 0 A%3E%3C + Font%3E%3C a Black a P%3E%3Ca%20href c Span%3E%3C i Yourwebmasterresources t Font%3E%3C Span%3E%3C p Span%3E%3C nsearch3 Font%3E%3C % A%3E%3C C Yourwebmasterresources bsearch searchocl Black 2searchjvsearchsrctl02+javascriptp Font%3E%3C tsearch3%searchC searchctl02+javascript%searchCsearch%search0 Font%3E%3C r Span%3E%3C fsearchp Yourwebmasterresources e Font%3E%3C rc P%3E%3Ca%20href Tweetcache control in htaccess
correct syntax for cache control headers gsdv




msg:4053099
 2:56 am on Jan 3, 2010 (gmt 0)
looking for help with correct syntax for cache control and how to properly separate and not cache https pages in a php cart...

# Set up Expires and cache control headers
ExpiresActive On
#
<FilesMatch "(401¦403¦404¦410¦500)\.html¦htm$">
ExpiresDefault A0
ErrorHeader set cache-control: "no-store"
</FilesMatch>
#
#<FilesMatch "\.(xml¦txt)$">
ExpiresDefault A28800
Header set cache-control: "no-cache, public, must-revalidate"
</FilesMatch>
#
<FilesMatch "\.(ico¦pdf¦flv¦jpg¦jpeg¦png¦gif¦js¦css¦swf)$">
ExpiresDefault A604800
Header set cache-control: "no-cache, public, must-revalidate"
</FilesMatch>
#

 

jdMorgan




msg:4053370
 8:31 pm on Jan 3, 2010 (gmt 0)

You'll need separate cache-control code in the .htaccess file(s) in your HTTPs directory-structure (As usually implemented, HTTP and HTTPS files should be separated at least by directory).

Without knowing the details of your set-up, all I can do is recommend a couple of efficiency tweaks to your patterns. Use the power of regular-expressions to avoid testing "html" and "htm" separately, to avoid the fatal flaw in the logical structure of that pattern (any .htm file was matched regardless of filename, and so would have been marked as non-cacheable), and also put the filename and filetypes in order from most-likely-to-be-requested to least-likely-to-be-requested for efficiency:

<FilesMatch "(401¦403¦404¦410¦500)\.html¦htm$"> --> <FilesMatch "(401¦403¦404¦410¦500)\[b].(h[/b]tml¦ht[b]m)[/b]$"> --> <FilesMatch "(404¦403¦401¦410¦500)\.ht[b]ml?$[/b]">
#
# ...
#
<FilesMatch "\.(ico¦pdf¦flv¦jpg¦jpeg¦png¦gif¦js¦css¦swf)$">
--> <FilesMatch "\.(gif¦jp[b]e?g[/b]¦png¦css¦js¦ico¦pdf¦swf¦flv)$">

As always, replace all broken pipe "¦" characters you see in this forum with solid pipes before use; Posting on this forum modifies the pipe characters.

The suggested order of filenames/filetypes is just a guess based on a typical site's request profile; You may want to make further adjustments based on a quick check of your site's stats.

Jim

gsdv




msg:4053539
 5:47 am on Jan 4, 2010 (gmt 0)

hi jim,

thank your for the reply. the willingness to help others on this site is phenomenal. the inquiries are for a zen cart store setup on an apache server.

"Without knowing the details of your set-up..."

# Set up Expires and cache control headers
ExpiresActive On
#
<FilesMatch "(404¦403¦401¦410¦500)\.html?$">
ExpiresDefault A0
ErrorHeader set cache-control: "no-store"
</FilesMatch>
#
#<FilesMatch "\.(xml¦txt)$">
ExpiresDefault A28800
Header set cache-control: "no-cache, public, must-revalidate"
</FilesMatch>
#
<FilesMatch "\.(gif¦jpe?g¦png¦css¦js¦ico¦pdf¦swf¦flv)$">
ExpiresDefault A604800
Header set cache-control: "no-cache, public, must-revalidate"
</FilesMatch>
#

thank you.

Swanny007




msg:4053540
 5:58 am on Jan 4, 2010 (gmt 0)

As an aside, can this be used to set cache-control on specific filenames, or is it just for filetypes (extensions)?

gsdv




msg:4053547
 6:23 am on Jan 4, 2010 (gmt 0)

i think this would be correct for adding filenames
<FilesMatch "(filename¦filename¦filename)\.html$">

jdMorgan




msg:4053549
 7:01 am on Jan 4, 2010 (gmt 0)

gsdv,

If you want separate cache-control for SSL and non-SSL resources, then *some* method of telling them apart is required. This can be by filename or filetype if you are limited to just .htaccess in one single directory-path, or it can be based on two separate .htaccess files, one in the HTTP-accessible directory, and one in the HTTPS-accessible directory, in which case the directory is implicitly part of the condition under which the cache-control headers are constructed (because if the other directory is accessed, then the .htaccess code in this directory won't even run0. Other than implicit .htaccess-location-based qualification and the <Files> and <FilesMatch> containers, there are no other useful 'conditional' controls available at the .htaccess privilege level that can be used to qualify mod_headers and mod_expires directives for your current application.

If you have access to the server configuration, then you have a few more options.

The final option is to 'wrap' the entire site in a script, which can output the correct Cache-Control, Expires, Last-Modified, Content-Type, and other HTTP response headers, and then "include" the requested resource (e.g. the requested "file") and send its contents to the requesting client. This can be viewed as using a script to replace almost the entire Apache content-handling phase.

I don't know how your files are disposed in regard to separate SSL/non-SSL directories or what privilege levels you have, and so cannot provide any other suggestions.

---

swanny,

You can use any part of the filename with <FilesMatch>, including the name, file-extension, or both, but do be aware that <Files> and <FilesMatch> examine the filename only: They don't look at the URL, and they don't consider the directory path. They only consider the name of the file as it would appear in a directory-listing. So if you have two files which match the <FilesMatch> pattern, and these two files are in different directories, but both are in or below the directory in which the .htaccess file with the <FilesMatch> directive is located, then *both* files will be affected. If that's not desirable, then the code can be moved into .htaccess files in each of those two files' own directories, and different cache-control settings can then be applied separately to each of them.

Simply-put, part of the scope of .htaccess code execution is based on the directives in that .htaccess file, and part of it is based on the location of that .htaccess file.

Jim

gsdv




msg:4053858
 6:35 pm on Jan 4, 2010 (gmt 0)

hi jim,

is there any problem with just adding this cache control (below). and then waiting to see if it helps or hurts and then add more cache control directives in a modular fashion?
#
<FilesMatch "\.(gif¦jpe?g¦png¦css¦js¦ico¦pdf¦swf¦flv)$">
ExpiresDefault A604800
Header set cache-control: "no-cache, public, must-revalidate"
</FilesMatch>
#
also what would be the equivalent syntax for adding the cache control above to the html headers instead of in the htaccess? for example using meta tags, or ?...

thank you

jdMorgan




msg:4054549
 4:17 pm on Jan 5, 2010 (gmt 0)

Cache-control headers in the <head> section of HTML files are largely a waste of time, since browsers don't need them and network caches do not look at the content-body of HTTP responses, and so will never even 'see' the HTML.

Also, consider whether you really need to revalidate those media filetypes. Doing so means that the browser will send an If-Modified-Since request to your server every time, and that (in most cases) your server will (have to) respond with a 304-Not Modified status response. It's usually better to simply mark those filetypes with a Expires header and leave the Cache-Control header blank (unset). Then if you need to 'override' a previously-cached object on an emergency basis, it's usually far more efficient to simply re-name it on the server, thus avoiding any need for page-load-by-page-load revalidation of included objects that almost never change. nYourwebmasterresources Black Fr Font%3E%3C A%3E%3C Font%3E%3C Span%3E%3C P%3E%3Ca%20href Your Webmaster Resources cache control in htaccess Apache Web Server forum at WebmasterWorld y Your Webmaster Resources x Your Webmaster Resources Your Webmaster Resources Your zYourwebmasterresources Black Fr Font%3E%3C A%3E%3C Font%3E%3C Span%3E%3C P%3E%3Ca%20href Your Webmaster Resources cache control in htaccess Apache Web Server forum at WebmasterWorld t n Your Webmaster Resources Your Webmaster Resources