How can I rewrite a url to append a header with Apache

301 views Asked by At

I have an Apache instance that is receiving requests in the form of https://www.example.com/some_path/rpc/x/y/z.pbf that include among others a header OIDC_CLAIM_foo = "[1,2]"

How can I rewrite the URL so that when it includes "rpc" the header is appended as part of the query string i.e: https://www.example.com:3000/other_path/rpc/x/y/z.pbf?foo=[1,2]

Is it possible to urlencode the [1,2] part of the query?

1

There are 1 answers

0
Thakkie On BEST ANSWER

Try this

It checks wether the header OIDC_CLAIM_foo exists an is not empty.

If so it appends the value to the current request_uri

It also checks if the query parameter foo does exist to prevent infinite loops

RewriteCond %{HTTP:OIDC_CLAIM_foo} ^(.+)$
RewriteCond %{QUERY_STRING} !foo
RewriteRule ^(.*/rpc/.*)$ /$1?foo=%1 [L]