Skip to content

Instantly share code, notes, and snippets.

@jdmsft
Last active February 24, 2020 14:47
Show Gist options
  • Save jdmsft/a9f213e6dcd2e183d5d2df1141431be9 to your computer and use it in GitHub Desktop.
Save jdmsft/a9f213e6dcd2e183d5d2df1141431be9 to your computer and use it in GitHub Desktop.
# Get the application gateway
$gw = Get-AzApplicationGateway -Name ApplicationGateway -ResourceGroupName "MyWAF"
# Get the existing HTTPS listener, because it had already exists
$httpslistener = Get-AzApplicationGatewayHttpListener -Name appGatewayHttpsListener -ApplicationGateway $gw
# Get the HTTP listener, because it had already exists
$listener = Get-AzApplicationGatewayHttpListener -Name appGatewayHttpListener -ApplicationGateway $gw
# Add a redirection configuration using a permanent redirect and targeting the existing listener
Add-AzApplicationGatewayRedirectConfiguration -Name redirectHttptoHttps -RedirectType Permanent -TargetListener $httpslistener -IncludePath $true -IncludeQueryString $true -ApplicationGateway $gw
# Get the redirect configuration
$redirectconfig = Get-AzApplicationGatewayRedirectConfiguration -Name redirectHttptoHttps -ApplicationGateway $gw
# Add a new rule to handle the redirect and use the new listener
Add-AzApplicationGatewayRequestRoutingRule -Name "HTTPRule_RedirectToHTTPS" -RuleType Basic -HttpListener $listener -RedirectConfiguration $redirectconfig -ApplicationGateway $gw
# Update the application gateway
Set-AzApplicationGateway -ApplicationGateway $gw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment