0

I'm working in a configuration for an API rest, and I want to deny all the routes except the use by the API.

I'm trying to make this Allow all the query_string with match with /rest or /rest/* in it. Deny the rest of the routes.

<If "%{QUERY_STRING} =~ /rest/">
  Require all granted
</If>
<Else>
  Require all denied
</Else>

I only get denied for all the routes.

1
  • Your configuration looks correct. I suggest that you try turning on debug logging to figure out why your regexp doesn't match the query string. (You do this by changing the usual LogLevel warn to LogLevel debug in your main config file.)
    – Jenny D
    Jul 4, 2019 at 9:42

1 Answer 1

-1

You can to deny all in your main Directory, and allow all in the rest location.

Something like this:

 <Directory /path/to/your/docroot>
   Require all denied
   ...
 </Directory>
 ...
 <LocationMatch "^/rest">
   Require all granted
 </LocationMatch>
2
  • That would work if the question was about locations - but it's about the query string, i.e. the part that comes after a ? in the URI.
    – Jenny D
    Jul 4, 2019 at 9:36
  • The questions says "deny all excepts some routes". The sample code is trying to do this checking the query_param but IMHO is a wrong approach (probably because of a clean URL functionality). So, the proposed answer denies all routes but not the ones beginning with "/rest".
    – sanzante
    Jul 4, 2019 at 10:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .