Menü schliessen
Created: May 2nd 2025
Last updated: May 26th 2025
Categories: Common Web Development,  IT Development
Author: Tim Fürer

HTACCESS: Only Allow Access for Specified IP Addresses

Tags:  Apache,  cybersecurity,  guide,  htaccess,  web
Donation Section: Background
Monero Badge: QR-Code
Monero Badge: Logo Icon Donate with Monero Badge: Logo Text
82uymVXLkvVbB4c4JpTd1tYm1yj1cKPKR2wqmw3XF8YXKTmY7JrTriP4pVwp2EJYBnCFdXhLq4zfFA6ic7VAWCFX5wfQbCC

Sometimes you wish to protect certain areas of your server by denying access except for a select few. Here's an easy whitelist setup for allowing only clients from specified IP addresses to access your content using Apache2 .htaccess rules.


Setup

Order deny,allow

Deny from all

Allow from 12.345.678.9
  • The first rule (Order deny, allow) explicitly states the order in which to apply the following rules.
  • The next rule (Deny from all) defines as a basis that all connections shall be denied.
  • The last rule (Allow from 12.345.678.9) sets an exception for connections from the IP address "12.345.678.9" . Be sure to insert the IP address that you actually want to allow.

If you'd like to whitelist more IP addresses, simply add more "Allow from {IP}" declarations. For example, like so:

Order deny,allow

Deny from all

Allow from 12.345.678.9

Allow from 98.765.432.1

Allow from 127.0.0.1