ghell Posted January 7, 2008 Share Posted January 7, 2008 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). Quote Link to comment https://forums.phpfreaks.com/topic/84931-setting-up-cache-time-for-files-in-a-directory/ Share on other sites More sharing options...
steviewdr Posted January 8, 2008 Share Posted January 8, 2008 .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 Quote Link to comment https://forums.phpfreaks.com/topic/84931-setting-up-cache-time-for-files-in-a-directory/#findComment-433405 Share on other sites More sharing options...
ghell Posted January 8, 2008 Author Share Posted January 8, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/84931-setting-up-cache-time-for-files-in-a-directory/#findComment-433435 Share on other sites More sharing options...
steviewdr Posted January 8, 2008 Share Posted January 8, 2008 My way should be best This confirms: http://httpd.apache.org/docs/2.0/mod/mod_headers.html -steve Quote Link to comment https://forums.phpfreaks.com/topic/84931-setting-up-cache-time-for-files-in-a-directory/#findComment-433505 Share on other sites More sharing options...
ghell Posted January 8, 2008 Author Share Posted January 8, 2008 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) Quote Link to comment https://forums.phpfreaks.com/topic/84931-setting-up-cache-time-for-files-in-a-directory/#findComment-433618 Share on other sites More sharing options...
steviewdr Posted January 8, 2008 Share Posted January 8, 2008 "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 Quote Link to comment https://forums.phpfreaks.com/topic/84931-setting-up-cache-time-for-files-in-a-directory/#findComment-433671 Share on other sites More sharing options...
ghell Posted January 9, 2008 Author Share Posted January 9, 2008 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) Quote Link to comment https://forums.phpfreaks.com/topic/84931-setting-up-cache-time-for-files-in-a-directory/#findComment-434658 Share on other sites More sharing options...
steviewdr Posted January 10, 2008 Share Posted January 10, 2008 "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 Quote Link to comment https://forums.phpfreaks.com/topic/84931-setting-up-cache-time-for-files-in-a-directory/#findComment-435721 Share on other sites More sharing options...
ghell Posted January 11, 2008 Author Share Posted January 11, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/84931-setting-up-cache-time-for-files-in-a-directory/#findComment-436137 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.