To restrict access to selected directories on an Apache web server based on IP address, you can use the Require
directive in the Apache HTTPD configuration file or in a .htaccess file.
The Require
directive specifies the requirements that must be met in order for a client to access the specified directory. You can use the Require ip
or Require host
directive to specify an IP address or hostname that is allowed to access the directory, or you can use the Require not ip
or Require not host
directive to specify an IP address or hostname that is not allowed to access the directory.
Here is an example of using the Require
directive to restrict access to a directory named /restricted
based on IP address:
<Directory /restricted> Require ip 10.10.0.0/16 Require not ip 10.10.10.0/24 </Directory>
This directive will allow clients with an IP address in the range 10.10.0.0
to 10.10.255.255
to access the /restricted
directory, except for clients with an IP address in the range 10.10.10.0
to 10.10.10.255
. All other clients will be denied access to the directory and will receive a 403 Forbidden error.
Keep in mind that the exact syntax and options for the Require
directive may vary depending on your specific Apache installation and configuration. It is always a good idea to refer to the official Apache documentation for detailed instructions and further information.