irules redirection and something extra

I have a requirement for creating an irule which will add the site id to the forwarded url on https The iRule should redirect requests for

cmsint-qa.abc.com/public/header.html?SiteId=GCR

To

https://gcr-qa.abc.com/public/header.html

If the rule can be written in such a way that the SiteId is added to “-qa.abc.com/public/header.html” with HTTPS

Any help would be appreciated

How about something like this:

when HTTP_REQUEST {
    if { not ( [URI::query [string tolower [HTTP::uri]] siteid] equals "" ) } {
        set siteid [URI::query [string tolower [HTTP::uri]] siteid]
        HTTP::redirect "https://${siteid}-qa.abc.com/public/header.html"
    }
}

Thanks Kevin So this whole piece of code is forwarding the URL and adding the site id to the forwarded url header.html as well?

If the request URI contains a “siteid” query string, it is redirected to the new URI.