Understanding htaccess Filesmatch code

泪湿孤枕 提交于 2020-01-14 11:41:06

问题


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

It's a HUGE pain

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>

回答1:


FilesMatch allows you to match files using a regular expression.

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

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

For example:

\.(engine|inc ...)$|

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

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:

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.

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



来源:https://stackoverflow.com/questions/18676012/understanding-htaccess-filesmatch-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!