IP Addressing on Apache

I need to block access to the entire site through the IP address, except for the url / api, which should be open to everyone.

I am currently using ...

<LocationMatch /admin>
    Order Deny,Allow
    Deny from all
    Allow from [MY IP]
</LocationMatch>

this blocks access URLs starting with / admin. But I want to block all urls except those that run / api.

Chris

+1
source share
2 answers
RewriteEngine On # (only needs to happen once in .htaccess files.

RewriteBase /
RewriteCond %{REMOTE_ADDR} !^10\.103\.18\.104     # <--YOUR IP HERE
RewriteCond %{REQUEST_URI} !^/api    # page or directory to ignore                   
RewriteRule ^(.*)$ http://example.com/no_access.html [R=401] # where to send blocked requests
+2
source

Ok, you can block the whole site first and then just enable / api.

<LocationMatch />
    Order Deny,Allow
    Deny from all
    Allow from [MY IP]
</LocationMatch>

<LocationMatch /api>
    Order Deny,Allow
    Allow from all
</LocationMatch>

Sorry, I couldn’t verify it due to the way XAMPP was configured on my PC. Pray for it.

0
source

Source: https://habr.com/ru/post/1772248/


All Articles