Apache的附加尾随斜线我重写规则 [英] Apache appends trailing slash to my rewrite rule
问题描述
我有干净的路径具有相同名称的现有目录。
I have clean path with the same name as existing directory.
我使用这些规则的.htaccess支持清洁路径,路径:
I use these .htaccess rules to support clean path for the path:
RewriteCond ${REQUEST_URI} ^/mydir
RewriteCond ${REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
一切工作正常(我有一个MYDIR清洁路径的工作,我可以访问直接/ mydir目录现有文件),但是Apache追加结尾的斜线所有的时间要求。
我要求 http://domain.com/mydir
,并重定向我 301
到 http://domain.com/mydir/
。
everything works correctly (I have a "mydir" clean path working and I can access existing files in the /mydir directory directly), but apache appends the trailing slash all the time to requests.
I request http://domain.com/mydir
, and it redirects me 301
to http://domain.com/mydir/
.
这是什么原因?
推荐答案
/ MYDIR /
被称为Apache模块添加后尾随斜线 mod_dir
,增加了所有目录后斜线。这是由于该设置在默认情况下打开的:
Trailing slash after /mydir/
is added by an Apache module called mod_dir
that adds a trailing slash after all the directories. This is due to this setting turned on by default:
DirectorySlash On
您可以通过关闭它:
DirectorySlash Off
然而,它可能会通过展示其上市暴露出一些目录。
However it might expose some directories by showing their listings.
关闭最后的斜线重定向可能会导致信息 信息披露。考虑这样的情况mod_autoindex是活性 (选项+指标)和DirectoryIndex的被设置为有效的资源(例如, index.html的),并有该URL定义没有其他特殊的处理。 在这种情况下,以斜线的请求将呈现的index.html 文件。但是,如果没有后面的斜杠的请求将列出目录 内容。
Turning off the trailing slash redirect may result in an information disclosure. Consider a situation where mod_autoindex is active (Options +Indexes) and DirectoryIndex is set to a valid resource (say, index.html) and there's no other special handler defined for that URL. In this case a request with a trailing slash would show the index.html file. But a request without trailing slash would list the directory contents.
这篇关于Apache的附加尾随斜线我重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!