Understanding htaccess Filesmatch code

13,141

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)

Share:
13,141

Related videos on Youtube

SimaPro
Author by

SimaPro

Updated on June 05, 2022

Comments

  • SimaPro
    SimaPro almost 2 years

    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>