.htaccess deny access to specific files? more than one

前端 未结 3 1798
予麋鹿
予麋鹿 2020-12-05 08:19

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

相关标签:
3条回答
  • 2020-12-05 08:23

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

    <FilesMatch ^((home|test|file)\.php$|mysecretfolder|asecretpicture\.jpe?g)$>
    ...
    </FilesMatch>
    
    0 讨论(0)
  • 2020-12-05 08:33

    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.

    0 讨论(0)
  • 2020-12-05 08:43

    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>
    
    0 讨论(0)
提交回复
热议问题