How to restrict viewing of files in a directory

I have a directory that contains many confidential PDF documents. If someone knew the file name, they could just go around my login system and view the file as if it were an image.

If I moved the directory from the document root, how would I show it to the user after logging in? I will need to return the requested file to the root directory of the document, but not sure how to do it.

If there are any other suggestions besides removing the directory from the root, I am also open to this. Thank.

+1
source share
2 answers

Listen to the file through PHP so you always know who / when / what will load.

+2
source

Add the following line to .htacces:

RewriteRule ^(dir_name_1|dir_name_2)/? /error/404 [L]
0

All Articles