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:
- Log in to your Plesk account.
- Navigate to the "Files" section of your domain.
- Use the file manager to locate the
.htaccessfile. This file is typically found in the root directory of your website (often labeled as/httpdocs/). - If you do not see a
.htaccessfile, 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.
- Edit the
.htaccessfile using a text editor. - Add the following line to block a specific IP address:
Deny from 123.456.789.012
- 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.
- Edit the
.htaccessfile using a text editor. - Add the following line to block a specific IP address:
Require not ip 123.456.789.012
- 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
.htaccessfile. 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 fromorRequire not ip). - File Permissions: Make sure that the
.htaccessfile has the correct permissions set (usually 644). - Contact Support: If you continue to experience issues, contact Internetport support for assistance.