How to ban access to a site by editing the .htaccess file

How to Restore WordPress Site With Only Database Backup
SSL: What it is, what it is for and how to install it

Prohibit access to a site is not something you routinely do as we build a website to publicize something, is not it? But in some cases it can happen and you need to lock your all access the site and stay active only for you, maybe when testing or installing new plugins.

This tutorial will teach you how to ban access to a website via the .htaccess file. After running this step by step, users will come across the 403 error on your website. So make sure of the reasons that led him to prohibit access.

What will you need

Before starting, prepare the following:

Access to cPanel of your hosting account or access to the FTP client.

static IP address. If you have a dynamic IP address, this tutorial may not work for you.

Step 1 – Opening your .htaccess file

The file .htaccess is in your directory public_html . You can access it using the File Manager in your cPanel or connecting to your account by FTP client such as FileZilla.

Note that the .htaccess is a hidden file, so you need to enable visibility.

Step 2 – Verifying IP address

You need to know your own IP address to allow yourself able to access your site. In your browser, open the link and note its IP address.

How to check my IP

Step 3 – Editing the .htaccess file

Add the following line at the top of your .htaccess file:

Order Deny, Allow Deny from all Allow from YourIPAdress

See below how it would look:

editing .htaccess file

Do not forget to click save changes to save the changes.

IMPORTANT! If you block your own access to your site, make sure your address and IP has not changed. If you have a dynamic IP address, this tutorial is not suitable for you, as we’ve warned earlier.


You learned how to prohibit access to a site, blocking your site to all users except for you. You can also prohibit access to specific countries visitors in this tutorial.