I have a directory ("files") where sub-directories and files are going to be created and stored over time. The directories also need to deliver a directory listing, using "options indexes", but only if a user is authenticated, and authorized. I have that part built, and working, by doing the following:
<Directory /var/www/html/files>
Options Indexes
IndexOptions FancyIndexing SuppressHTMLPreamble
HeaderName /includes/autoindex/auth.php
</Directory>
Now I need to take care of file delivery. To force authentication for files, I have built the following:
RewriteCond %{REQUEST_URI} -f
RewriteRule /files/(.*) /auth.php
I also tried:
RewriteCond %{REQUEST_URI} !-d
RewriteRule /files/(.*) /auth.php
Both directives are not redirecting to auth.php when I request:
foo.com/files/bar.pdf
foo.com/files/baz/bar.pdf
Ideas?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^/files/(.*) /auth.php?file=$1 [NC,L]
REQUEST_FILENAME
for this and not REQUEST_URI
RewriteEngine on
(.*)
to be passed to your script, you need to tell Apache how/where to pass the value by using a $1
^
to the beginning of your rule to make sure you're matching /files/blah.txt
and not, say, /foo/files/blah.txt
. [NC,L]
to tell Apache to use case-insensitive matching and to stop processing rules on this match.
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.