Restrict folder and files with .htaccess

3

I have the following directory:

examples
    file.php
    file2.php
helpers
    file3.php
secret
    .htaccess
    index.html
    file.json
.gitignore
index.php
README.md

My .htaccess file contains the following:

RewriteEngine On

# Protect the htaccess file
<Files .htaccess>
Order Allow,Deny
Deny from all
</Files>

RewriteRule ^(secret/|*\.json) - [F,L,NC]

<Files "*.json">
Order Allow,Deny
Deny from all
</Files>

When entering the secret folder by url link it does not show me anything (this works fine) but if I enter the .json file inside this folder link if you show me the content

How can I fix my .htaccess so that it does not show the contents of that file?

    
asked by Jorius 22.02.2017 в 15:21
source

2 answers

1

With this rule you hide all the files with the indicated extension (no listings are shown) and if you try to access them by the url it gives you an error 403, I think it could help you:

<Files ~ "(.json)">
    Order allow,deny
    Deny from all
</Files>
    
answered by 22.02.2017 / 16:23
source
1

with this you would restrict all * .json

<Files "*.json">
Order Deny,Allow
Deny from all</Files>
    
answered by 22.02.2017 в 15:48