How to Use .htaccess deny from all to Restrict All Access
If you’re currently testing your site or setting it to maintenance mode, you might want to restrict visitors from accessing it. In this tutorial, we’ll show you exactly how to do it using the deny from all command in the .htaccess file.
What Is .htaccess?
.htaccess stands for “Hypertext Access”, it’s a configuration file used by Apache-based web servers to modify the server’s behavior. You can also utilize the file for other purposes, such as creating a password for your site, changing your site’s time zone, making a custom error page, changing the default index page, or redirecting URLs. Adding a few commands to .htaccess can make all of this happen.
How to Edit the .htaccess File?
If you want to edit the .htaccess file, you can do so by entering the root folder of your site through your hosting control panel’s file manager or an FTP client. Here’s how to do it using Hostinger’s hPanel:
- Log in to the hPanel.
- Enter the File Manager, located under the Files section.
- Access the public_html directory.
- Look for the .htaccess file, right-click on it, and choose edit.
If you can’t find the .htaccess file in the public_html directory, you can create it yourself. Just click the New File button at the top right corner of the file manager, name it .htaccess, then click Create.
How to Use .htaccess deny from all to Restrict All Access?
To restrict all access except for your IP address, you need to add the deny from all command to the .htaccess file. Here’s how:
order allow,deny
deny from all
allow from IP
Replace IP with your IP address to create the exception. If you want to allow access from all IP addresses but restrict access from a specific one, you can use this format:
order allow,deny
deny from UndesiredIP
allow from all
Replace UndesiredIP with the IP address you want to restrict. Make sure to save the .htaccess file to apply the changes.
If you want to block access from specific countries, you can check out our other article here.
Conclusion
Now you know how to restrict access to your site using the deny from all command in the .htaccess file. Don’t forget to allow access to your own IP address! If you have any further questions, let us know in the comment section below.
Author
Edvinas P. is a Backend Developer at Hostinger. During his free time, he likes to play Airsoft and play music with his band.
👉
Start your website with Hostinger – get fast, secure hosting here 👈
🔗 Read more from MinimaDesk:
- The Ultimate Guide to WP-Content: Access, Upload, and Hide Your WordPress Directory
- How to Add and Customize RSS Feeds in WordPress
- How Many WordPress Plugins Are Too Many? Best Practices for Performance Optimization
- How to Fix Broken Permalinks in WordPress: A Step-by-Step Guide
🎁 Download free premium WordPress tools from our Starter Tools page.