Deny Access to Files, Folders through htaccess – Deny from All

How to deny access to files, folders through htaccess file. In this tutorial, We are going to learn .htaccess directives through which we can deny direct access to files and folders.

How to Deny Access to Files, Folders through htaccess

How to Deny Access to Files, Folders through htaccess

What is .htaccess File?

.htaccess is a configuration file used by a web server (Apache). The full form of htaccess is Hypertext Access. Htaccess files are used to override server global configuration for the directory level in which you place this file.

.htaccess file contain directives, which is read by webserver (Apache) and apply them to the directory level where this htaccess file is placed.

Why we use the .htaccess File?

The .htaccess file is very useful when

i) You don’t have an access to httpd.conf file (Apache main configuration file).
ii) You want to enforce some directory level configuration.

Imagine you have more than one website running on the same server and you want to configure different rules for each website. In that case, you won’t change global configuration (httpd.conf file) as it applies to both the websites. In that case, the .htaccess file is an ideal way to specify changes.

Application of .htaccess File

There are a lot of things you can do through by using the .htaccess file. Here’s the list of some useful things you can easily do by using the .htaccess file.

Password Protect a Folder through .htaccess

URL Rewriting – Create Seo-Friendly through .htaccess

Subscribe Our Tutorials

Get Latest Updates on Facebook

How to Prevent Image hotlinking through .htaccess File

How to Leverage browser Caching through .htaccess File

How to Deny Access to Files, Folders through htaccess

To prevent direct access of all the files and folders of your project. Create a .htaccess file in the root of your project directory structure. Then open the .htaccess file and write this directive deny from all.

Now you are done. If you want to check whether this directive is working or not. Try to access any file or folder of your project. You will get the following message.

How to Password Protect Folder through .htaccess

How to Deny Access to a Certain File Types through .htaccess

Now we have discussed how to prevent direct access to files and folders through .htaccess. But sometimes we need to prevent certain file types for direct access. Let’s understand how to prevent the access of certain file types.

How to Deny Access to all Files with .php Extension through htaccess

How to Deny all Files with .inc Extension

How to Deny Access to a Single File through .htaccess

Suppose, I want to prevent an access to a specific file. Let’s take an example of config file which has all the system configuration. config.php is one example, you can include any PHP file. To disallow the access to single you need to mention the file name in .htaccess.

Deny access to config.php file through htaccess

2. How to Deny Access to .htaccess file.

How to Prevent Any Direct Directory Browsing through htaccess

Deny access to an app folder.

Put this code in your .htaccess file to prevent any direct directory browsing through the browser.

There is a lot of things which can be done through .htaccess files. Read How to leverage browser caching through .htaccess file

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , , . Bookmark the permalink.