This article will guide you through blocking specific IP addresses or IP ranges on your website hosted by Internetport using the .htaccess file. This method is particularly useful if you want to restrict access to certain parts of your site from unwanted visitors.

Finding Your .htaccess File in Plesk

To modify the .htaccess file, you first need to locate it within your hosting environment. If you are using Plesk as your control panel, follow these steps:

  1. Log in to your Plesk account.
  2. Navigate to the "Files" section of your domain.
  3. Use the file manager to locate the .htaccess file. This file is typically found in the root directory of your website (often labeled as /httpdocs/).
  4. If you do not see a .htaccess file, you can create one by clicking on "Create File" and naming it exactly .htaccess.

Blocking an IP Address Using .htaccess

You can block specific IP addresses or ranges using either the Deny from directive (for older Apache versions) or the Require not ip directive (recommended for Apache 2.4 and later).

Using Deny from Directive

This method is suitable if your server runs an older version of Apache.

  1. Edit the .htaccess file using a text editor.
  2. Add the following line to block a specific IP address:
Deny from 123.456.789.012
  1. To block an entire range of IPs, specify the subnet mask:
Deny from 123.456.789.

Using Require not ip Directive

This method is recommended for Apache 2.4 and later versions.

  1. Edit the .htaccess file using a text editor.
  2. Add the following line to block a specific IP address:
Require not ip 123.456.789.012
  1. To block an entire range of IPs, specify the subnet mask:
Require not ip 123.456.789.

Unblocking an IP Address

If you need to unblock an IP address that was previously blocked, simply remove or comment out the corresponding line in your .htaccess file.

  • To comment out a line, prepend it with a hash symbol (#):
# Require not ip 123.456.789.012

Troubleshooting

If you encounter issues after modifying your .htaccess file, consider the following:

  • Check Syntax: Ensure that there are no syntax errors in your .htaccess file. A single typo can cause server errors.
  • Apache Version: Verify which version of Apache is running on your server to use the correct directive (Deny from or Require not ip).
  • File Permissions: Make sure that the .htaccess file has the correct permissions set (usually 644).
  • Contact Support: If you continue to experience issues, contact Internetport support for assistance.