[英]mod_rewrite in conjunction with “options indexes”
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: 当我请求时,这两个指令都不会重定向到auth.php:
foo.com/files/bar.pdf foo.com/files/bar.pdf
foo.com/files/baz/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
REQUEST_FILENAME
而不是REQUEST_URI
RewriteEngine on
RewriteEngine on
启用了Rewrite (.*)
to be passed to your script, you need to tell Apache how/where to pass the value by using a $1
(.*)
传递到脚本,则需要使用$1
告诉Apache如何/在何处传递值。 ^
to the beginning of your rule to make sure you're matching /files/blah.txt
and not, say, /foo/files/blah.txt
. ^
,以确保您匹配的是/files/blah.txt
而不是/foo/files/blah.txt
。 [NC,L]
to tell Apache to use case-insensitive matching and to stop processing rules on this match. [NC,L]
告诉Apache使用不区分大小写的匹配,并停止对此匹配进行处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.