2

I need to configure my Apache (2.4) in a way, that It prevents answering requests that

  1. don't come from the same IP as the server

  2. match a specific pattern in the URL

In pseudocode it must look something like this, but I'm having a hard time translating this in valid Apache config syntax

<If "%{CLIENT_IP} != %{SERVER_IP} &&  %{REQUEST_URL} contains 'abcde' ">
  Require all denied
</If>

1 Answer 1

0

You can create a list of allowed IPs and then compare the page or directory accessed against it.

SetEnvIfNoCase Remote_Addr 192.0.2.4 allow_ip #AllowedServer1
SetEnvIfNoCase Remote_Addr 192.0.2.6 allow_ip #AllowedServer2

<Directory /home/YOURSITE/public_html/secret/>
    <RequireAll>
        require env allow_ip
    </RequireAll>
</Directory>

Following the above code, access to the directory example.com/secret will only be allowed for IPs 192.0.2.4 and 192.0.2.6. Apache will deny access with a 403 error to all other visitors.

1
  • How does this answer the question. The OP is not asking about particular IP addresses, but rather a pattern. Aug 5 at 0:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.