的.htaccess拒绝所有,除?htaccess

由网友(眼里起雾)分享简介:我有这样的htaccess的规则来阻止所有的.xml请求:I have this htaccess rule to block all .xml requests:Order allow,denyDeny from allSatisfy all不过,我需要...

我有这样的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.

阅读全文

相关推荐

最新文章