nginx rewrite query not firing

I'm probably missing something obvious - but I don't know what it is. And this is probably a duplicate; I've read through hundreds os questions here on nginx rewrites - but they don't appear to match my use case.

The problem I am trying to solve is to implement a workaround for CAS where the client application tells CAS the return URL is HTTP when actually its HTTPS. The serverside was managing to untangle this up until Google decided to release v87 which gets upset about https->http redirects. I am therefore trying to change the URL sent to CAS. I want to replace "http" with "https" in the query, e.g.

https://cas.example.com/cas/login?service=http:%2F%2Fapp.example.com/

should be re-written as

https://cas.example.com/cas/login?service=https:%2F%2Fapp.example.com/

Here's my config

location / {
            ## this one works....
            # rewrite /foo/(.*) /$1 break;

            ## these don't....
            # rewrite ^([^\?]+)\?service=http:(.*)$ $1?service=https:$2 break;
            # rewrite ^([^\?]+)\?service=http%(.*)$ $1?service=https%$2 break;
            rewrite /(.*)vice=http:(.*) /$1vice=https:$2 break;
            rewrite /(.*)vice=http%(.*) /$1vice=https%$2 break;
            rewrite /(.*)vice=http(.*) /colin.bip?f=$1vice=other$2 break;
            rewrite /(.*)foo(.*) /$1bar$2 break;

(there are no other location blocks in this server).

When I say the others don't work, I mean that the URL is not changed.

The regexes appear to parse the URL correctly when I test them in a separate PCRE implementation but do not seem to be firing in my nginx config.

UPDATED I enabled the rewrite logging - and the rewrites appear to ignore the query part?

 *1 "/(.*)foo(.*)" does not match "/url.php", client: 10.1.1.7, server: example.com, request: "GET /url.php?q=foo&service=http://hello HTTP/1.1"

Can I convince nginx to rewrite the query too?


As per update, rewrite regexes are not applied to the query part of the URL. I was able to solve my problem with:

            if ($args ~* "(.*)vice=http(:|%3A)(.*)") {
                    set $newqry "$1vice=https:$3" ;
                    rewrite ^(.*)$ $1?$newqry? break;
            }

(the trailing '?' after newqry suppresses the addition of the original query to the URL).