简体   繁体   中英

.htaccess deny access to specific files? more than one

I am able to disable access to a file with .htaccess, but I don't know how to disallow multiple files to be viewed (directly, not from includes)

They are .php so I can't disable a file type (like the only tutorials online say..)

<FILES ... ? 

</FILES>

Or something.. For example "home.php, file.php , test.php" how do I disallow access to all three files with that tag? or similar, help please!

If you want to exclude files based on regular expressions, you could use FilesMatch instead of Files, eg:

<FilesMatch ^((home|test|file)\.php$|mysecretfolder|asecretpicture\.jpe?g)$>
...
</FilesMatch>

Looks like you have to exclude those files one by one:

<files home.php>
Deny/Allow/Whatever
</files>
<files file.php>
...

You can use *.gif in <files> or something* , but as home.php, file.php and test.php can't really be grouped with a "*", this is probably the only way to go.

since apache 2.4

<FilesMatch "\.htaccess|config\.php">

    Require all denied

</FilesMatch>

instead of

<FilesMatch "\.htaccess|config\.php">

    Order allow,deny 
    Deny from all 

</FilesMatch>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM