How to prevent direct file access from a directory on server?

Friends, Here is a simple approach to prevent the direct file access from a directory on a server.

To do this we need to create a file .htaccess and just write a single line of code:

Deny From All

To prevent direct file access put the .htaccess file with the above line of code in the directory containing the file.

Sample Directory Without .htaccess File:
server1

Output when accessing the pages/page1.html:
sout1

Sample Directory With .htaccess File:
server3

Output when accessing the pages/page1.html:
sout2

To prevent direct file access from a directory, just place the .htaccess file with following lines of text i.e. “Deny From All” in that directory.