---
title: "How to prevent access to a specific file in htaccess"
description: "The .htaccess file is a hidden text file within your hosting account that can be very powerful. It is designed so that you can modify it to change the behavior of your website that normally would..."
url: https://www.inmotionhosting.com/support/website/htaccess-prevent-access/
date: 2012-11-15
modified: 2021-08-16
author: "Scott Mitchell"
categories: ["Website"]
type: post
lang: en
---

# How to prevent access to a specific file in htaccess

The .*htaccess* file is a hidden text file within your hosting account that can be very powerful. It is designed so that you can modify it to change the behavior of your website that normally would take higher access beyond your account. It acts as a liaison between your domain and the server and can perform many functions.

There may be times when you want to restrict direct access to specific files that reside in your account. The server itself will still be able to access the file and use the information. This can be done via the htaccess file. Below are the instructions for preventing access to specific files via the .htaccess file.

**Preventing access to certain files via htaccess**

1. First, you will need to [log into your cPanel](/support/edu/cpanel/how-to-log-into-cpanel/) to access the htaccess file.
2. Find the **Files **category and click on the **File Manager** icon. [![cpanel](https://www.inmotionhosting.com/support/wp-content/uploads/2012/11/edu_htaccess_select-cpanel.png)](/support/wp-content/uploads/2012/11/edu_htaccess_select-cpanel.png)
3. In order to select a different domain click on the **Settings** in the top right corner. For addon domains, click on the dropdown and find your desired addon domain name. Be sure the checkbox next to **Show Hidden Files** is checked. Click the **Save** button to enter the *File Manager*. [![file-manager-show-hidden](https://www.inmotionhosting.com/support/wp-content/uploads/2012/11/edu_htaccess_select-settings.png)](/support/wp-content/uploads/2012/11/edu_htaccess_select-settings.png)
4. You should now be in the root folder of the domain you chose. Look for the *.htaccess* file and right click on it. This brings up a menu. Find and click on the **Edit **option. If you get a popup box, simply find and click the **Edit **button in the lower right corner to continue to the editor. [![file-manager-htaccess](https://www.inmotionhosting.com/support/wp-content/uploads/2012/11/edu_htaccess_select-htaccess-file.png)](/support/wp-content/uploads/2012/11/edu_htaccess_select-htaccess-file.png)
5. You are now in the htaccess editor. Paste the following code in the file to prevent access to your selected file. In our example below, we decided to hide the file named filetohide.jpg. This can be a file of any tyep (html, jpg, php, etc.) `# the following prevents display of the filetohide file <files filetohide.jpg> order allow,deny deny from all </files>`
6. Be sure to hit the **Save Changes** button in the upper right corner to save your new htaccess configuration.
