How block access to url directory

2019-09-07 05:30发布

问题:

I have the follow link : www.mysite.com/uploads/file.pdf

I want the user to download the file. But I do not want him vizualize files from this directory. How can I do this?

I'm using PHP and Apache.

回答1:

Even better use Options -Indexes in your .htaccess file

create a file named .htaccess on that directory and add Options -Indexes as the content of the file. Make sure you hit enter after adding Options -Indexes

This will make sure that your directory will not be index able . i.e you can access the file say www.mysite.com/uploads/file.pdf but you cannot list all the files in that directory using www.mysite.com/uploads/



回答2:

Adding an empty file called index.html into the directory www.mysite.com/uploads/ will prevent the user from being able to see(visualize) the files.

Disabling directory indexes will also work How do I disable directory browsing?