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
- First, you will need to log into your cPanel to access the htaccess file.
- Find the Files category and click on the File Manager icon.
- 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.
- 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.
- 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
deny from all
- Be sure to hit the Save Changes button in the upper right corner to save your new htaccess configuration.
Support Center LoginOur Login page has moved, Click the button below to be taken to the login page.
2018-08-09 10:26 am
I want to hide my sitemap from competitors. not for search engines. Is it possible above-mentioned .htaccess tutorial? Please help me with this to enhance the developer's knowledge.
2018-08-09 3:19 pm
You could try renaming the file to something difficult to guess and submitting it to search engines afterwards. You can see other options within this Stack Exchange forum. I hope this proves helpful for you.