Introduction
Azure Application Gateway URL redirection rules can create infinite redirect loops when HTTP-to-HTTPS rules conflict with backend responses or when the target URL incorrectly points back to the gateway itself.
Symptoms
Browser redirect loop:
The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.curl showing redirect chain:
```bash $ curl -I http://myapp.example.com
HTTP/1.1 301 Moved Permanently Location: https://myapp.example.com
$ curl -I https://myapp.example.com
HTTP/1.1 301 Moved Permanently Location: https://myapp.example.com # Loop detected - redirecting to itself ```
Application Gateway logs:
{
"requestUri": "https://myapp.example.com/",
"responseCode": 301,
"redirectUrl": "https://myapp.example.com/"
}Common Causes
- 1.Redirect target is self - Rule redirects to same URL
- 2.Backend sends redirect - Backend also redirects, creating chain
- 3.Listener port mismatch - HTTPS listener on wrong port
- 4.Rule priority conflict - Multiple rules match same request
- 5.Host header mismatch - Host header changed by rule
- 6.Path-based rule issue - Path pattern redirects incorrectly
- 7.Missing SSL certificate - HTTPS listener without certificate
Step-by-Step Fix
- 1.Check logs for specific error messages
- 2.Verify configuration settings
- 3.Test network connectivity
- 4.Review recent changes
- 5.Apply corrective action
- 6.Verify the fix
Step 1: Check Redirect Rules
```bash # List all redirect rules az network application-gateway rule list \ --gateway-name my-appgw \ --resource-group my-rg \ --query '[].{Name:name,Type:type,Redirect:redirectConfiguration}'
# Check redirect configuration az network application-gateway redirect-config show \ --gateway-name my-appgw \ --resource-group my-rg \ --name http-to-https \ --query '{TargetType:targetType,TargetUrl:targetUrl,IncludePath:includePath,IncludeQuery:includeQueryString}' ```
Step 2: Fix HTTP-to-HTTPS Redirect
```bash # Correct redirect configuration for HTTP to HTTPS az network application-gateway redirect-config update \ --gateway-name my-appgw \ --resource-group my-rg \ --name http-to-https \ --target-listener https-listener \ --include-path true \ --include-query-string true
# Verify redirect targets HTTPS listener, not URL az network application-gateway redirect-config show \ --gateway-name my-appgw \ --resource-group my-rg \ --name http-to-https \ --query 'targetListener.id' ```
Step 3: Check Listener Configuration
```bash # List all listeners az network application-gateway listener list \ --gateway-name my-appgw \ --resource-group my-rg \ --query '[].{Name:name,Port:port,Protocol:protocol,Host:hostNames}'
# Verify HTTPS listener has SSL certificate az network application-gateway listener show \ --gateway-name my-appgw \ --resource-group my-rg \ --name https-listener \ --query '{Port:port,Protocol:protocol,SslCertificate:sslCertificate.id}'
# If missing certificate, add it az network application-gateway listener update \ --gateway-name my-appgw \ --resource-group my-rg \ --name https-listener \ --ssl-cert my-ssl-cert ```
Step 4: Verify Backend Pool Settings
```bash # Check backend pool configuration az network application-gateway address-pool show \ --gateway-name my-appgw \ --resource-group my-rg \ --name my-backend-pool \ --query '{Addresses:backendAddresses,BackendHost:hostNames}'
# Check backend HTTP settings az network application-gateway http-settings show \ --gateway-name my-appgw \ --resource-group my-rg \ --name my-http-settings \ --query '{Port:port,Protocol:protocol,HostName:hostName,PickHostName:pickHostNameFromBackendAddress}'
# If backend sends redirects, use correct protocol az network application-gateway http-settings update \ --gateway-name my-appgw \ --resource-group my-rg \ --name my-http-settings \ --protocol Https \ --port 443 ```
Step 5: Check Rule Priority and Path Patterns
```bash # List rules with priorities az network application-gateway rule list \ --gateway-name my-appgw \ --resource-group my-rg \ --query '[].{Name:name,Priority:ruleType,Listener:listener,Action:actionType}'
# Check path-based rules az network application-gateway url-path-map show \ --gateway-name my-appgw \ --resource-group my-rg \ --name my-path-map \ --query '{DefaultRule:pathRules[0],PathRules:pathRules}'
# Ensure path rules don't redirect to themselves ```
Step 6: Check for Backend Redirects
```bash # Test backend directly (bypass gateway) curl -I http://backend-ip:8080/
# If backend returns redirect, fix backend configuration # Or configure gateway to handle backend redirect
# Check backend response headers az network application-gateway http-settings show \ --gateway-name my-appgw \ --resource-group my-rg \ --name my-http-settings \ --query '{Port:port,Protocol:protocol,TrailingSlash:redirectToBackend}' ```
Step 7: Fix Host Header Settings
```bash # Host header issues can cause redirects # Check if host header is preserved az network application-gateway http-settings show \ --gateway-name my-appgw \ --resource-group my-rg \ --name my-http-settings \ --query '{HostName:hostName,PickHost:pickHostNameFromBackendAddress,BackendHost:backendHostNames}'
# Preserve original host header: az network application-gateway http-settings update \ --gateway-name my-appgw \ --resource-group my-rg \ --name my-http-settings \ --pick-host-name-from-backend-address false ```
Step 8: Test with Diagnostic Logs
```bash # Enable diagnostic logging az monitor diagnostic-settings create \ --name appgw-logs \ --resource /subscriptions/SUB/resourceGroups/my-rg/providers/Microsoft.Network/applicationGateways/my-appgw \ --workspace /subscriptions/SUB/resourcegroups/my-rg/providers/microsoft.operationalinsights/workspaces/my-workspace \ --logs '[{"category":"ApplicationGatewayAccessLog","enabled":true}]'
Step 9: Use Rewrite Rules Instead
```bash # For complex scenarios, use rewrite rules az network application-gateway rewrite-rule create \ --gateway-name my-appgw \ --resource-group my-rg \ --rule-set-name rewrite-set \ --name force-https \ --response-headers '[{"headerName":"Location","headerValue":"https://myapp.example.com"}]'
# Apply rewrite rule to listener az network application-gateway rule update \ --gateway-name my-appgw \ --resource-group my-rg \ --name my-rule \ --rewrite-rule-set rewrite-set ```
Step 10: Remove Conflicting Rules
```bash # Delete conflicting redirect rules az network application-gateway rule delete \ --gateway-name my-appgw \ --resource-group my-rg \ --name conflicting-rule
# Ensure only one rule handles HTTP to HTTPS az network application-gateway rule list \ --gateway-name my-appgw \ --resource-group my-rg \ --query '[?redirectConfiguration!=null].name' ```
Redirect Configuration Types
| Type | Use Case | Example |
|---|---|---|
| Permanent (301) | SEO migration | Old URL to new |
| Temporary (302) | Short-term redirect | Maintenance page |
| Found (303) | POST to GET | Form submission |
| Permanent (308) | HTTP to HTTPS | Preserve method |
Verification
```bash # After fixing redirect configuration # Test HTTP request curl -I http://myapp.example.com
# Expected: # HTTP/1.1 301 Moved Permanently # Location: https://myapp.example.com/
# Test HTTPS request (should NOT redirect) curl -I https://myapp.example.com
# Expected: # HTTP/1.1 200 OK # (No Location header, content served)
# Check gateway health az network application-gateway show-health \ --gateway-name my-appgw \ --resource-group my-rg ```
Prevention
To prevent Azure Application Gateway redirect loop issues from recurring, implement these proactive measures:
1. Monitor Redirect Patterns
groups:
- name: azure-appgateway
rules:
- alert: AzureAppGatewayRedirectLoop
expr: |
rate(azure_appgateway_redirect_loops_total[5m]) > 0
for: 2m
labels:
severity: critical
annotations:
summary: "Azure Application Gateway redirect loop detected"2. Validate Redirect Configuration
```bash # Pre-deployment validation script cat << 'EOF' > validate_redirects.sh #!/bin/bash # Check for common redirect loop patterns
# HTTP to HTTPS redirect should only apply to HTTP listener az network application-gateway redirect-config show \ --gateway-name my-appgw \ --resource-group my-rg \ --name http-to-https \ --query '{TargetListener:targetListener.id,IncludePath:includePath}'
# Should target HTTPS listener, not the same HTTP listener EOF
chmod +x validate_redirects.sh ```
3. Document Redirect Rules
```bash # Export and document redirect configuration az network application-gateway redirect-config list \ --gateway-name my-appgw \ --resource-group my-rg \ -o yaml > redirect_rules.yaml
# Add comments documenting purpose # git add redirect_rules.yaml # git commit -m "Document redirect rules" ```
Best Practices Checklist
- [ ] Monitor redirect patterns
- [ ] Validate redirect configuration before deployment
- [ ] Document redirect rules
- [ ] Test redirects manually
- [ ] Use separate listeners for HTTP/HTTPS
- [ ] Review redirect targets carefully
Related Issues
- [Fix Azure Application Gateway WAF Blocking](/articles/fix-azure-application-gateway-waf-blocking)
- [Fix Azure Backend Pool Not Resolving](/articles/fix-azure-backend-pool-not-resolving)
- [Fix Azure SSL Certificate Binding Failed](/articles/fix-azure-ssl-certificate-binding-failed)
Related Articles
- [Technical troubleshooting: Fix Azure Aks Pod Crashloopbackoff Issue in Azure](azure-aks-pod-crashloopbackoff)
- [Technical troubleshooting: Fix Azure Api Management Policy Expression Runtime](azure-api-management-policy-expression-runtime-error)
- [Technical troubleshooting: Fix Azure App Configuration Feature Flag Not Refre](azure-app-configuration-feature-flag-not-refreshing)
- [Technical troubleshooting: Fix Azure App Service 503 Always On Disabled Issue](azure-app-service-503-always-on-disabled)
- [Technical troubleshooting: Fix Azure Application Gateway Err SSL Unrecognized](azure-application-gateway-err-ssl-unrecognized-name-alert)
<script type="application/ld+json"> { "@context": "https://schema.org", "@type": "TechArticle", "headline": "Fix Azure Application Gateway Redirect Loop", "description": "Troubleshoot Azure Application Gateway redirect loops. Fix HTTP-to-HTTPS rules, listener configurations, and backend settings.", "url": "https://www.fixwikihub.com/fix-azure-redirection-rule-loop", "publisher": { "@type": "Organization", "name": "FixWikiHub", "url": "https://www.fixwikihub.com" }, "author": { "@type": "Person", "name": "FixWikiHub Editorial Team" }, "datePublished": "2026-04-03T10:21:56.050Z", "dateModified": "2026-04-03T10:21:56.050Z" } </script>