Get a Pentest and security assessment of your IT network.

Cyber Security

Block IP Addresses in Apache (XAMPP/Windows)

TL;DR

This guide shows you how to block an IP address that’s making too many requests to your Apache web server running on XAMPP for Windows. We’ll use the .htaccess file, which is a simple way to control access without restarting the server.

Steps

  1. Find Your .htaccess File
    • The .htaccess file is usually in your XAMPP web root directory. This is typically C:xampphtdocs.
    • If you don’t see a .htaccess file, create one using a plain text editor (like Notepad). Make sure it’s saved as .htaccess and *not* .htaccess.txt*.
  2. Edit the .htaccess File

    Open the .htaccess file in a text editor.

  3. Add Block Rules

    To block a specific IP address, add the following line to your .htaccess file:

    Order Deny,Allow
    Deny from 123.45.67.89
    Allow from all
    • Replace 123.45.67.89 with the IP address you want to block.
    • Important: The order of these lines matters! Order Deny,Allow tells Apache to check the Deny rules first.
  4. Block a Range of IPs (Optional)

    You can block an entire range of IP addresses using CIDR notation:

    Order Deny,Allow
    Deny from 192.168.1.0/24
    Allow from all
    • Replace 192.168.1.0/24 with the IP range you want to block. /24 represents a common subnet mask (255.255.255.0).
  5. Multiple Blocks

    You can add multiple Deny from ... lines to block several IP addresses or ranges:

    Order Deny,Allow
    Deny from 123.45.67.89
    Deny from 10.0.0.10
    Deny from 192.168.1.0/24
    Allow from all
  6. Save the .htaccess File

    Save your changes to the .htaccess file.

  7. Test the Block
    • Try accessing your website from the blocked IP address. You should see a '403 Forbidden' error or similar message.
    • If it still works, clear your browser cache and try again.
  8. Using mod_access (Alternative - Less Common)

    While .htaccess is easier for most users, you can also use the mod_access module directly in Apache's configuration files. This requires restarting the Apache server.

    • Edit your Apache configuration file (usually httpd.conf or a similar file within the XAMPP config directory).
    • Add lines like this inside a <Directory ...> block:
      <Directory /var/www/html>
        Order Deny,Allow
        Deny from 123.45.67.89
        Allow from all
      </Directory>
    • Restart the Apache server for the changes to take effect.

Important Notes

  • Syntax Errors: Be careful when editing .htaccess! A syntax error can cause your entire website to become inaccessible. If this happens, remove or comment out the lines you added and try again.
  • IP Address Changes: Blocked IP addresses may change over time. You'll need to update your .htaccess file if an address changes.
  • Dynamic IPs: Blocking dynamic IP addresses (those that change frequently) can be difficult and unreliable.
  • cyber security: This method provides a basic level of cyber security by preventing access from specific sources, but it's not a comprehensive solution. Consider using more advanced techniques like a web application firewall (WAF) for stronger protection.
Related posts
Cyber Security

Zip Codes & PII: Are They Personal Data?

Cyber Security

Zero-Day Vulnerabilities: User Defence Guide

Cyber Security

Zero Knowledge Voting with Trusted Server

Cyber Security

ZeroNet: 51% Attack Risks & Mitigation