Denying IP Addresses with .htaccess Print

  • 0

Denying IP Addresses with .htaccess

To deny specific IP addresses access to your website using the .htaccess file, you can follow these steps:

  1. Access Your .htaccess File:

    • Log in to your cPanel account.
    • Navigate to File Manager.
    • Locate and open the public_html directory (or the directory where your WordPress installation is).
    • Find the .htaccess file. If it’s hidden, ensure you enable Show Hidden Files (dotfiles) in the settings.
  2. Edit Your .htaccess File:

    • Right-click on the .htaccess file and select Edit.
    • If prompted, confirm to edit the file.
  3. Add Deny Rules:

    • At the top or bottom of the .htaccess file, add the following lines to deny specific IP addresses:
    plaintext
    Copy code
    # Deny access to specific IP addresses Order Deny,Allow Deny from 123.456.789.000 Deny from 111.222.333.444

    Replace 123.456.789.000 and 111.222.333.444 with the actual IP addresses you want to block.

  4. Save Changes:

    • Click Save Changes to apply your modifications.

Example

Here’s how the relevant section of your .htaccess file might look:

plaintext
Copy code
# BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress # Deny access to specific IP addresses Order Deny,Allow Deny from 123.456.789.000 Deny from 111.222.333.444

Notes

  • You can deny multiple IP addresses by adding more Deny from lines.
  • If you want to allow all other IP addresses while denying certain ones, ensure the Order Deny,Allow line is included.
  • To deny a range of IP addresses, you can use wildcards. For example, Deny from 123.456.789 will block all IPs starting with 123.456.789.

Conclusion

Using .htaccess to deny IP addresses is a straightforward way to enhance your website's security. If you encounter any issues, double-check the syntax and ensure your .htaccess file is correctly formatted.


Was this answer helpful?

« Back