简体   繁体   中英

How to allow directory listing with htacess, but disable browser caching?

I have an XML directory on an Apache 2.2.14 server (Ubuntu 10.04). I simply want to enable people to download files from this directory by providing a link to it from my PHP application.

The problem is that browsers cache their initial file list and don't update to show new files unless F5 is pressed. This directory gets a lot of new files and while it doesn't need real-time updates, I would appreciate not having to write a note in the footer reminding customers they need to F5 to see the file they just uploaded.

Bonus question: Could I just put Options -Indexes in httpd.conf to avoid creating a root .htaccess file?

httpd.conf

ServerName localhost
FileETag none
ExpiresActive On
ExpiresDefault "access plus 30 days"
ExpiresByType text/html A86400

root .htaccess file:

Options -Indexes

XML directory .htaccess file

Options +Indexes
IndexIgnore .. *.shtml
IndexOptions SuppressHTMLPreamble XHTML HTMLTable SuppressDescription Charset=UTF-8 NameWidth=*
HeaderName HEADER.shtml
ReadmeName README.shtml
AddType text/xml .xml

HEADER.shtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
  <head>
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="-1">
  </head>
  <body>

README.shtml

  </body>
</html>

Might be worth pointing out that this is how the link is open via javascript:

var newWin = window.open(url,name,'height=800,width=600,menubar=no,titlebar=0,resizable=yes,toolbar=no,scrollbars=yes,screenX=100,screenY=100,dependent=no');
newWin.focus();

我将ExpiresActive Off添加到XML目录.htaccess文件中 ,并且目录列表现在始终是最新的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM