Create an Application Gateway with Redirect

Azure Public Test Date Azure Public Test Result

Azure US Gov Last Test Date Azure US Gov Last Test Result

Best Practice Check Cred Scan Check

Deploy To Azure Deploy To Azure US Gov Visualize

This template illustrates different redirect scenarios Application Gateway supports:

  1. Redirect http requests to https.
  2. Redirect requests to a fixed url.
  3. Redirect requests under a given path.

This functionality can be configured using RedirectConfiguration.

Property Mandatory Description
RedirectType Y Supported http redirection types - Permanent, Temporary, Found, SeeOther
TargetListener N Reference to a listener to redirect the request to.
TargetUrl N A Url to redirect to. Cannot be used when TargetListener is specified.
IncludePath N True/False.
IncludeQueryString N True/False

Sample Redirect Configuration

{
    "redirectConfigurations": [
        {
            "Name": "redirectConfig1",
            "properties": {
                "redirectType": "Found",
                "targetListener": {
                    "id": "[concat(variables('applicationGatewayID'), '/httpListeners/appGatewayHttpsListener1')]"
                }
            }
        }
    ]
}

A RedirectConfiguration can be associated with either a listener in a basic rule, Or a Pathrule in UrlPathMap.

Sample Configuration with Basic Rule

{
    "requestRoutingRules": [
        {
            "Name": "rule1",
            "properties": {
                "RuleType": "Basic",
                "httpListener": {
                    "id": "[concat(variables('applicationGatewayID'), '/httpListeners/appGatewayHttpListener1')]"
                },
                "redirectConfiguration": {
                    "id": "[concat(variables('applicationGatewayID'), '/redirectConfigurations/redirectConfig1')]"
                }
            }
        }
    ]
}

Sample Configuration with UrlPathMap

{
    "urlPathMaps": [
        {
            "name": "urlPathMap1",
            "properties": {
              "defaultRedirectConfiguration": {
                "id": "[concat(variables('applicationGatewayID'), '/redirectConfigurations/redirectConfig2')]"
              },
                "pathRules": [
                    {
                        "name": "pathRule1",
                        "properties": {
                            "paths": [
                                "[parameters('pathMatch1')]"
                            ],
                            "redirectConfiguration": {
                                "id": "[concat(variables('applicationGatewayID'), '/redirectConfigurations/redirectConfig1')]"
                            }
                        }
                    }
                ]
            }
        }
    ]
}

Notes:

Supported apiVersion to use http redirect feature is "2017-04-01" and above.

Tags: Microsoft.Network/publicIPAddresses, Microsoft.Network/virtualNetworks, Microsoft.Network/applicationGateways