Home > Tutorials > HTACCESS Tutorials > Denying Site Access

Denying Site Access

Denying and allowing access to your website can be accomplished very easily with .htaccess. In order to block an IP address you would use the following command within your .htaccess file:

deny from

Replace with the IP address you wish to block. If you only specify one or two groups of the numbers you will block a whole range of IP’s.

You can also use .htaccess to deny everyone access to a directory except for scripts. For example lets say that you have all your database passwords and configuration files in a folder called configs. You want to be able to include the files inside that folder using PHP in most of your webpages, but you don’t want them to be accessible via the internet. In order to accomplish this you would create a new .htaccess file and place it into the configs folder and place the following command into it:

deny from all

This would prevent that directory from being publicly accessible, however PHP will still be able to use it freely.

Furthermore instead of using numeric addresses, domain names (and subdomain names) can also be used to ban users. For example:

deny from myisp.com

This bans users with a remote hostname ending in myisp.com. This would stop all users connected to the internet via myisp.com from viewing your site.

Take note that using .htaccess to block an entire range or name is likely to lock out innocent users. Please use with caution.

About Michael Boguslavskiy

Michael Boguslavskiy is a full-stack developer & online presence consultant based out of New York City. He's been offering freelance marketing & development services for over a decade. He currently manages Rapid Purple - and online webmaster resources center; and Media Explode - a full service marketing agency.

Check Also

Understanding The <BASE> Tag in 2018

The <BASE> tag has been a part of HTML for decades now, and little has ...

Like every other website, this site uses cookies to analyze our traffic. Cookies may also be utilized by our advertisers and partners. By using this website you agree to the use of said cookies. More Information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings, continuing to navigate past this message, or you click "Accept" below then you are consenting to the use of cookies on the Rapid Purple website.