mod_rewrite的:如果重定向什么,但一个文件 [英] mod_rewrite: Redirect if anything but a file
问题描述
我有一个Apache的.htaccess到目录此.htaccess文件当前所在的父目录的文件。这工作完全重定向所有请求的要求。不过,我想它,以便在该目录中,如果请求的是一个有效的文件(而不是目录),忽略了主要的重写规则。
I have an Apache .htaccess file in the parent directory to directory this .htaccess file is currently located. This works perfectly redirecting all requests as required. However, I would like it so in this directory, if the request is for a valid file (and NOT a directory), ignore the main rewrite rule.
目前,以下将关闭目录改写为好,而且我想不通为什么。
Currently, the following turns off the rewrite for directories as well, and I can't figure out why.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !-d
RewriteCond %{REQUEST_URI} -f
RewriteRule . - [L]
</IfModule>
由于任何人谁贡献。
Thanks to anyone who contributes.
推荐答案
尝试 REQUEST_FILENAME
而不是 REQUEST_URI
:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule . - [L]
REQUEST_URI
并只包含URI路径,但Apache需要测试agains一个绝对的文件系统路径 -d
和 -f
。和 REQUEST_FILENAME
保存对应于当前请求的URI的绝对文件系统路径。
REQUEST_URI
does only contain the URI path but Apache needs an absolute file system path to test agains -d
and -f
. And REQUEST_FILENAME
holds the absolute file system path corresponding to the current requested URI.
这篇关于mod_rewrite的:如果重定向什么,但一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!