How do I deny access to certain IP addresses? (.htaccess)

This article applies to 123-reg Linux Shared Hosting accounts.

This process is useful if you have information on your website that you only want certain people to see. To set this up, you will need to create a .htaccess file:

1

Open Notepad or a similar text editor.

2

Copy and paste the following text into your new .htaccess file:

<Limit GET HEAD POST>
order allow,deny
deny from 215.49.8.17
deny from 159.64.9.
allow from all
</LIMIT>

In your .htaccess file, amend the above code, changing the IP addresses to suit your needs. Each command should be on a separate line.

3

Save the file with the file name .htaccess.

4

Ensure that the file type is set to All Files.

5

Click the Save button.

Tip: You can deny access based upon an IP address or an IP block. The above process blocks access to the site from 215.49.8.17, and from any subdomain under the IP block 159.64.9. (159.64.9.1, 159.64.9.2, etc.). This can be very useful if there is another site linking directly to your images or content.

You can set an option for Deny From All, which would deny everyone access. You can also allow or deny access by domain name rather than IP address (Allow From .123-reg.co.uk works for www.123-reg.co.uk or support.123-reg.co.uk, etc).

Answer options

Your feedback was successfully added.

Answer tracking

Track

Watch the content of this article for changes.