0

I'm using ProxyPass for two URLs (A and B below) that both include a question mark and the string 850: -

A: https://frontend.com/850/home?session=25575 -> https://backend.com/850/home?session=25575

B: https://frontend.com/home?session=25575/850 -> https://backend.com/home?session=25575/850

Note that in the above URLs that the 850 string occurs both before and after the question mark.

All advice seems to suggest that the way to deal with a question mark is with a rewrite rule. I would then like to 'lock it down' via LocationMatch (for string 850). Here is my apache code: -

RewriteEngine On
RewriteCond %{QUERY_STRING} .?
RewriteRule ^.?$  [B,NC,R=302,R]

        SSLProxyEngine on
        ProxyPreserveHost On
        <LocationMatch  "(.*)850(.*)">
                ProxyPass   https://backend.com/
                ProxyPassReverse   https://backend.com/
        </LocationMatch>

This works fine for URL A, but not for URL B.

How can I correct this such that it works for both URL A and B?

I've enabled LogLevel alert rewrite:trace6 and I can see in the log files that URL B above is getting translated to https://frontend.com/home? . Hence I cannot match it for the string 850 (already stripped).

5
  • LocationMatch applies to the path component of the URL only. Your second URL does not have the 850 in the path, but inside the query string. Commented Sep 20, 2024 at 10:06
  • Are you asking how to apply the proxy directives only to URLs that contain 850, either in the path or the query string? Then you probably better use an <if> conditional, httpd.apache.org/docs/2.4/mod/core.html#if - either to check if either REQUEST_URI or QUERY_STRING contain 850; or by checking against THE_REQUEST Commented Sep 20, 2024 at 10:11
  • In your URL B example you are also converting the query string from / to & - is that a typo or intentional? Commented Sep 21, 2024 at 23:50
  • MrWhite - that was a typo, now corrected. Sorry for the confusion, thanks Commented Sep 22, 2024 at 9:54
  • so now, I'm trying <If "%{THE_REQUEST} =~ m#850#"> Header always set test1 "IT WORKS" RewriteRule ^$ /404.html [R=404,NC,L] </If> but for some reason, it continues to process a locationmatch rule later. I would have thought that the 404 rewrite rule would work as a stop to all further processing. Commented Sep 22, 2024 at 13:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.