I need to trigger the apache authentications depending only on a URL parameter. For instance, The following URL http://mySillyApplication.com/items/browse?collection=9&sort_field=Title&num_items=10&... I need to trigger the authentication only if collection=9 . I've tried many things but I couldn't find how to do it. I think the key is to find a RewriteRule that could activate the LocationMatch .... just a guess:
RewriteEngine On
RewriteCond %{QUERY_STRING} (.*(?:^|&))collection=9((?:&|$).*) [NC]
RewriteRule (.*) - [R=401]
<LocationMatch "....don't know...">
AuthType Basic
AuthName "Login Required"
AuthUserFile /var/www/.../.htpwd
Require valid-user
Order allow,deny
Allow from all
Satisfy any
</LocationMatch>
Thanks.
You could use
<If> Directiveif Apache is 2.4.26 and later http://httpd.apache.org/docs/2.4/mod/core.html#ifSo, try the following code :