了解 htaccess 文件匹配代码 [英] Understanding htaccess Filesmatch code

查看:33
本文介绍了了解 htaccess 文件匹配代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 bluehost 托管网站上的子目录中安装 drupal...

I am trying to install drupal in a subdirectory on my bluehost hosted website...

这是一个巨大的痛苦

我认为 .htaccess 中的以下几行是问题所在.当我当前导航到 mysite.com/subdir/install.php 时,出现 403 错误.然而,当我从下面的行中去掉拒绝"时,我不再收到那个错误,所以我怀疑这条行引起了所有的麻烦.

I'm thinking the following lines from the .htaccess is the problem. When I currently navigatoe to mysite.com/subdir/install.php I get a 403 error. However, when I take out "deny" from the lines below, I cease to get that error, so I suspect that this line is causing all the trouble.

我的问题是,有人可以帮助我理解以下代码中发生的事情吗?特别是如果您可以按组件分解它.

My question is, can someone help me understand what is happening in the following code? Especially if you can break it down by component.

<FilesMatch ".(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(.php)?|xtmpl)(|~|.sw[op]|.bak|.orig|.save)?$|^(..*|Entries.*|Repository|Root|Tag|Template)$|^#.*#$|.php(~|.sw[op]|.bak|.orig.save)$">
      Order allow,deny
    </FilesMatch>

推荐答案

FilesMatch 允许您使用正则表达式匹配文件.

FilesMatch allows you to match files using a regular expression.

在上面的 FilesMatch 上,您有 4 组正则表达式,其中 1 组有一个辅助可选集.

On your above FilesMatch you have 4 sets of regular expression where the 1 set have an secondary optional set.

基本上它正在做的是禁止访问(错误 403)对您的正则表达式集描述的任何文件.

Basically what it is doing is forbidden access (error 403) to any of the files found that are described on your sets of regex.

例如:

.(engine|inc ...)$|

表示如果文件以 .engine 或 .inc 或 ... 规则的其余部分结尾,则拒绝对其进行访问.

Means if the file ends with .engine or .inc or ... rest of the rule, deny access to it.

然后在第一组规则的末尾有一个 | 就像上面的例子一样,代表 OR 所以如果第一组规则不匹配,它开始第二个,略有不同.

Then at the end of the first set of rules you have a | which like the above example, stands for OR so if the first set of rules were not match, it starts the second one, which is slight different.

^(..*|Entries.*|Repository)$

这里它做相反的事情,如果文件以给定的关键字开始和结束,它就会匹配,例如:

Here it does the opposite, it matches if the file starts and end with a given keyword, so for example:

如果文件以 . 开头,后跟任何内容,则 (.*) 表示其他任何内容,例如 .htaccess 或以 开头Entries 后跟任何内容或完全是 Repository 或 ... 直到最后.

If file starts with . followed by anything the (.*) means anything else for example .htaccess or starts with Entries followed by anything or is exactly Repository or ... till the end.

然后是下一条规则^#.*#$,这意味着文件以#作为其处理的#开始和结束字面意思

Then the next rule ^#.*#$, this one means the file starts and ends with a # as # its treated literally

最后一组规则与第一组规则相同,验证文件是否以给定的扩展名结尾.

And the last set of rules does the same of the first verify if file ends with those given extensions.

如果你想了解更多,我建议你了解更多关于Perl兼容正则表达式(PCRE)

If you want to know more then I suggest you to learn more about Perl Compatible Regular Expressions (PCRE)

这篇关于了解 htaccess 文件匹配代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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