Jump to content

Setting up cache time for files in a directory


ghell

Recommended Posts

I use some standard web hosting to host a large number of files that change infrequently (but do change). I do not have access to the server configuration as it is not dedicated or virtual hosting, just normal web hosting. I have had problems with users not being able to download an up to date version of a file when it changes, most likely because their ISP is caching the file. Is there any way I can put something in the directory that will either stop the ISP from caching it or set the cache expiry so that the ISP can be no more than a day behind the current copy of the file?

 

I can see from the http headers that the webserver is Apache/1.3.29 (Unix).

Link to comment
Share on other sites

.htaccess file:

----------------------------------------------------------------------------------------

# NEVER CACHE HOME PAGE

<FilesMatch "^\$">

  Header set Expires "Mon, 01 Jan 2007 12:00:00 GMT"

  Header set Cache-Control "no-store, no-cache, must-revalidate"

  Header set Pragma "no-cache"

</FilesMatch>

 

# NEVER CACHE (.HTM|.HTML|.TXT|.XML|.CSS) PAGES

<FilesMatch "\.(htm|html|txt|xml|css|)$">

  Header set Expires "Mon, 01 Jan 2007 12:00:00 GMT"

  Header set Cache-Control "no-store, no-cache, must-revalidate"

  Header set Pragma "no-cache"

</FilesMatch>

----------------------------------------------------------------------------------------

Note:  Lines that start with "#" are comments.

----------------------------------------------------------------------------------------

PS:  Don't forget to upload .htaccess again before trying to generate

your sitemap.

----------------------------------------------------------------------------------------

See: http://forums.cirtexhosting.com/showthread.php?t=2261

 

-steve

Link to comment
Share on other sites

Thanks for the info.

 

The htaccess in your post and the one in that link are quite different syntactically. What should it look like?

 

For example you use FilesMatch, that uses Files, You use Header set Key "value" while the link uses Header set Key: value

 

I would guess that Files and FilesMatch are either synonymous or similar and that quotation marks are only required if there are spaces in the literal, but what about the colon?

Link to comment
Share on other sites

Ok, looking around there I found things like FilesMatch = Files + Regular Expressions so it explained most of it.

 

Will <Files *> recurse or is it just the files in the current directory? I ask because the files I wish to make sure never get cached are as follows:

FileList.txt

Files/* (contains many subdirectories)

Link to comment
Share on other sites

"Will <Files *> recurse or is it just the files in the current directory?"

 

Yes - it will recurse into every subfolder beneath the one with the .htaccess file in it. If you only want 1 particular folder of files matched, only put the htaccess file in that.

 

-steve

Link to comment
Share on other sites

As soon as I uploaded the .htaccess file, it was automatically deleted. Does this mean that there was something wrong with the file, the Apache server does not have mod_headers or is it something more like the host not allowing them? (I would ask the host but the support isn't that great)

Link to comment
Share on other sites

"As soon as I uploaded the .htaccess file, it was automatically deleted."

 

Try again and try again.

If the .htaccess still gets deleted automatically, then Im afraid your out of luck. Ask your host support.

 

Make SURE that .htaccess just isn't hidden!!!

.htaccess is a hidden file on linux. So if your using a FTP program etc. try turning on hidden files. Also if your on windows try:

My Computer -> Tools (drop-down) -> Folder Options -> View (tab) -> (scroll down) Click "Show Hidden Files and Folders" (round button).

 

-steve

Link to comment
Share on other sites

Yea I use Linux at home so I am aware of Unix hidden files but it is not there as soon as I refresh the FTP client. I will try and get a reasonable answer out of the host's tech support but I'm not holding my breath. Oh well I'm changing hosts this month anyway.

 

Thanks for all your help :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.