How to free access to specific FOLDER or FILE using . htaccess?

Asked

Viewed 3,027 times

3

I have a . htaccess in my development environment.

Now I need to release a directory of the site, actually a specific PHP file.

I’m using this code on. htaccess, I am releasing several extensions, if I release the PHP extension, it accesses the file, but I do not want all PHP files to be released, I would like a specific one to be released.

order deny,allow
deny from all
<files ~ ".(xml|css|jpe?g|png|gif|js|otf|woff|svg)$">
allow from all
</files>

1 answer

0


Block access to files .PHP:

<Files *.php> 
    deny from all
</Files>

Authorize a specific file:

<Files "meuFicheiro.php">
    Order Allow,Deny
    Allow from all
</Files>
  • Mano what simplicity, I researched but found other more complex solutions that I did not need, but what I needed was exactly this here. Simple. Ours because I didn’t think of it before rsrsrsr

  • I have a question about this: If we happen to have several directories and subdirectories and in some of them there are files with this name meuFicheiro.php, but I just want to free access to the file meuFicheiro.php that is at the root leaving the others blocked for access? How to do?

  • @Carlosrocha In that case, there would have to be one .HTACCESS in folders to block access. At root it would not be necessary to have the lock since that file is to be accessible.

  • @Carlosrocha Anyway, this "design" of the organization is not the most functional given force to much more work. Ideal would be a folder with the authorized files and another one with files subject to lock.

  • Check it out: Rewritecond %{REQUEST_URI} ! /|manutencao.php$ [NC] Rewriterule . * index.php. This frees up any page named maintainance.php in all folders and subfolders of the system. Right? What I need is to release only the one at the root leaving blocked the others!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.