的.htaccess拒绝所有,除? [英] .htaccess deny all, except?

查看:102
本文介绍了的.htaccess拒绝所有,除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的htaccess的规则来阻止所有的.xml请求:

I have this htaccess rule to block all .xml requests:

<Files ~ "\.xml$">
Order allow,deny
Deny from all
Satisfy all
</Files>

不过,我需要允许一个特定的.xml文件。应如何规则重新写的?

However, I need to allow one certain .xml file. How should the rule be re-written?

此外,上述这条规则,我有这样一个例外:

Also, above that rule, I have an exception like this:

RewriteRule ^(myxml\.xml)$ $1 [L]

但是,这仍然不允许该文件

But that still doesn't allow the file.

推荐答案

Apache的正则表达式引擎是PCRE兼容,所以为什么不使用正则表达式为负向后断言(小于?!\ bmyxml) \的.xml $

The Apache Regexp Engine is PCRE compatible so why not use a regexp with a negative lookbehind assertion "(?<!\bmyxml)\.xml$"?

它说的是比赛的东西以.xml结束,只要它不是通过与myXML pceded $ P $。这意味着,该规则将不会触发myxml.xml,这样就不会被拒绝。

What this says is match something ending in .xml so long as it's not preceded by myxml. This means that the rule won't fire for myxml.xml, so it won't be denied.

BTW FilesMatch是根据Apache的文档〜pferred到文件$ P $。不要问我为什么。

BTW FilesMatch is preferred to Files ~ according to the Apache docs. Don't ask me why.

这篇关于的.htaccess拒绝所有,除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆