Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding htaccess Filesmatch code

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>
like image 801
SimaPro Avatar asked Sep 07 '13 17:09

SimaPro


People also ask

What is FilesMatch in htaccess?

htaccess file, the use of FilesMatch tags to block access to certain file extensions or to allow access to a specific list of filenames.

What is FilesMatch?

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.

What language does htaccess use?

htaccess files are written in the Apache programming language.


1 Answers

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)

like image 140
Prix Avatar answered Oct 16 '22 14:10

Prix