How to block access to a particular file on the server?

Asked

Viewed 142 times

-2

Basically, I have a file JSON in my project that contains information I wish not to access by typing in the address bar something like: www.meusite.com/file.json

And that goes for other files. How can I redirect the user to the home page if they type something like this?

1 answer

2


Through the archive .htaccess...

If you want to redirect you can add this line:

Redirect /caminho/para/arquivo.json http://dominio.com/arquivo/para/redirecionar.html

If you want to block (403 Forbidden code), enntão add this:

RewriteEngine On
RewriteRule ^/caminho/para/arquivo.json$ - [R=403,NC,L]
  • The redirect really works. The problem is that I need to read this file on other pages and it has become unavailable...

  • The file is unavailable if you try to access it directly from the browser, but you can still access it normally with PHP. So you can do something like: echo file_get_contents("arquivo.php"); and first define who has access

  • Um... this is nice. Sorry my inexperience kkkk but how do I define who has access?

  • Usually through authentication

Browser other questions tagged

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