There are several files.

exampletext1.php exampletext2.php exampletext3.php exampletext4.php 

How to prevent reading / execution of all files using .htaccess -
in the name of which is "exampletext" so that you do not have to "exampletext" each file.

Something like this, but not for specific files, but for those whose name contains "exampletext"

 <Files exampletext.php> Order Deny,Allow Deny from all </Files> 

    4 answers 4

    RTFM is the same ! A similar example is described in the Apache documentation in detail:

    The <FilesMatch> <Files> directive doesn’t have directives. However, it accepts a regular expression. For example:

     <FilesMatch ".+\.(gif|jpe?g|png)$"> # ... </FilesMatch> 

    would match most common Internet graphics formats.

    The files are named .png , or .gif , for example, are not matched. From the 2.4.8 onwards, the names of the groups and the backreferences are prefixed with the "MATCH_" and in the upper case. It can be referenced from within expressions and modules like mod_rewrite. In order to prevent confusion, numbered (unnamed) backreferences are ignored. Use named groups instead.

     <FilesMatch "^(?<sitename>[^/]+)"> require ldap-group cn=%{env:MATCH_SITENAME},ou=combined,o=Example </FilesMatch> 
    • this is not exactly the answer - hovdev
    • And what is your question? However, you are free to count as you like. - PinkTux
    • Well, you did not write a clear code that solves the problem, I know that there is apache documentation, but if I had time to sit down and carefully read the documentation, I would have done so :) - hovdev
    • Well, it seems they ask questions here, and get specific answers to them, nobody asks to razzhovyvat anything, you could just write the example I provided above, and everyone would be happy - hovdev
    • Following the example, there is in my answer (that is, in the Apache documentation). Exactly what is required in the question. - PinkTux

    After studying the Apache documentation on the advice and guidance of Pink Tux, thanks to him for this, I found the code that came up to me, though it differs from the above.

     <Files "exampletext??"> Order Deny,Allow Deny from all </Files> 
    • Is this for files that start with exampletext, or can this text be anywhere in the name? - Mae
    • it is checked for files that start with exampletext, but attentively! These 2 questions say that instead of them there can be any 2 characters, if you want an unlimited number of characters, use the code I wrote above, instead of question marks - one asterisk - hovdev
    • you can rearrange the asterisk if you want the file to end with this exampletext - hovdev

    here's the final working version, thanks to the apache and Pink Tux documentation for the tip

     <Files "exampletext*"> Order Deny,Allow Deny from all </Files> 
       <FilesMatch "exampletext"> Order Deny,Allow Deny from all </FilesMatch> 

      exampletext is not just a text, but a regular expression, it just happened that way in this question.

      • Thanks, will this code do what I listed above? I'll check it out - hovdev
      • Only it should be noted that there will be a ban on all files, in the name of which there is a substring exampletext , and not only strictly on exampletext*.php - PinkTux
      • Yes, I know, that's exactly what I need - hovdev
      • That's what the server replied to me :) 500 Internal Server Error Internal server error - hovdev
      • I deleted all the lines in .htaccess, wrote only your code, alas, it doesn’t work, something with code is hovdev