简体   繁体   中英

Azure Function App proxy is removing the query string

A simple, simple proxy redirect to our www subdomain is resulting in the query string being stripped off.

There is no reason for this.

Taken this URL.. https://mydomain.ok/whatever?foo=something

Should redirect to.. https://www.mydomain.ok/whatever?foo=something

Instead it currently redirects to.. https://www.mydomain.ok/whatever

Any help would be greatly appreciated. It's very hard to test this properly.

For the following, REDIRECT_TO_WEBSITE=www.domain.com

Here is the example configuration:

{
  "$schema": "http://json.schemastore.org/proxies",
  "proxies": {
    "api": {
      "matchCondition": {
        "route": "/api/{*path}"
      },
      "backendUri": "https://%WEBSITE_HOSTNAME%/api/{path}"
    },
    "rest": {
      "matchCondition": {
        "route": "{*rest}"
      },
      "responseOverrides": {
        "response.statusCode": "302",
        "response.headers.Location": "https://%REDIRECT_TO_WEBSITE%/{rest}",
      },
    }
  }
}

Found the answer on another SO question: Azure Function Proxies Multiple Query parameters with the same name

You simply need to add the request.querystring to the backend.request.querystring :

"requestOverrides": {
    "backend.request.querystring": "request.querystring"
}

So, your config would be:

{
  "$schema": "http://json.schemastore.org/proxies",
  "proxies": {
    "api": {
      "matchCondition": {
        "route": "/api/{*path}"
      },
      "backendUri": "https://%WEBSITE_HOSTNAME%/api/{path}"
      "responseOverrides": {
        "backend.request.querystring": "request.querystring"
      },
    },
    "rest": {
      "matchCondition": {
        "route": "{*rest}"
      },
      "responseOverrides": {
        "response.statusCode": "302",
        "response.headers.Location": "https://%REDIRECT_TO_WEBSITE%/{rest}",
        "backend.request.querystring": "request.querystring"
      },
    }
  }
}

It's worth pointing out that according to a commenter on that thread: "...going forward with .NET 6.0 onwards function proxies aren't supported, use API Management service instead"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM