DevHeads.net

restrict Location URL with special string

Hi,

I have URL like below (with ? and =)

<a href="http://myserver/?s=about" title="http://myserver/?s=about">http://myserver/?s=about</a>

What’s the correct syntax to allow only some IP.

<Location "/\?s\=about">
Require ip 127.0.0.1
</Location>

<Location "/?s=about">
Require ip 127.0.0.1
</Location>

<LocationMatch "about">
Require ip 127.0.0.1
</LocationMatch>

Nothing work.

Thanks in advance for any suggestion.
Regards.

Comments

Re: restrict Location URL with special string

By Rainer M. Canavan at 06/13/2018 - 09:03

<location> only matches the path part of the URL, not the query string
(i.e. the part after the ?).

There's an example for matching QUERY_STRING in
<a href="https://httpd.apache.org/docs/2.4/en/mod/core.html#if" title="https://httpd.apache.org/docs/2.4/en/mod/core.html#if">https://httpd.apache.org/docs/2.4/en/mod/core.html#if</a>

<If "%{QUERY_STRING} =~ /s=about/">
Require ip 127.0.0.1
</if>

may work, but I haven't tested it.

rainer

Re: restrict Location URL with special string

By Eric Covener at 06/13/2018 - 09:02

Those only match the path. In 2.2, use mod_rewrite. In 2.4, use <if>.