Tutorial: Configure URL-Based Content Routing
This tutorial guides you through setting up Azure Application Gateway to route traffic based on the URL path. This is useful for directing requests to different backend pools (e.g., microservices or different application versions) based on the requested URL.
Prerequisites:
- An Azure subscription.
- Basic understanding of Azure networking and Application Gateway concepts.
- Two or more functional web applications running on separate backend servers or services, accessible by Application Gateway.
Scenario Overview
We will configure Application Gateway to route traffic as follows:
- Requests to
/images/
will be sent to a backend pool serving static images. - Requests to
/videos/
will be sent to a backend pool serving video content. - All other requests will be sent to a default backend pool serving a general web application.

Steps to Configure URL Routing
-
Create Backend Pools
Ensure you have at least two backend pools configured in your Application Gateway. For this tutorial, let's assume:
- ImageBackendPool: Contains VMs or IP addresses hosting your image content.
- VideoBackendPool: Contains VMs or IP addresses hosting your video content.
- DefaultBackendPool: Contains VMs or IP addresses for your general web application.
-
Create HTTP Settings
Configure HTTP settings for each backend pool. You'll typically need separate settings if your backend applications listen on different ports or use different protocols (e.g., HTTP vs HTTPS).
- ImageHttpSettings: For the image pool (e.g., port 80, HTTP).
- VideoHttpSettings: For the video pool (e.g., port 80, HTTP).
- DefaultHttpSettings: For the default pool (e.g., port 80, HTTP).
-
Configure Listener
Create a listener to accept incoming traffic. For this tutorial, we'll use a single listener on port 80 for simplicity.
- Listener Name:
appgw-listener
- Frontend IP address: Select your frontend IP.
- Protocol: HTTP
- Port: 80
- Listener Name:
-
Create Request Routing Rules
This is the core step where you define the URL path matching and routing logic.
Navigate to Rules in your Application Gateway's configuration.
Rule 1: Default Rule
- Rule Name:
DefaultRule
- Priority: 1 (Lowest priority)
- Backend target: Select
DefaultBackendPool
andDefaultHttpSettings
. - Path-based routing: Select Yes.
- Add path: Click Add path.
- Backend target: Select
DefaultBackendPool
andDefaultHttpSettings
. - Path:
/*
(This acts as a catch-all for any path not explicitly defined).
Rule 2: Image Rule
- Rule Name:
ImageRule
- Priority: 2
- Listener:
appgw-listener
- Backend target: Select
ImageBackendPool
andImageHttpSettings
. - Path-based routing: Select Yes.
- Add path: Click Add path.
- Backend target: Select
ImageBackendPool
andImageHttpSettings
. - Path:
/images/*
- Path type: Prefix
Rule 3: Video Rule
- Rule Name:
VideoRule
- Priority: 3
- Listener:
appgw-listener
- Backend target: Select
VideoBackendPool
andVideoHttpSettings
. - Path-based routing: Select Yes.
- Add path: Click Add path.
- Backend target: Select
VideoBackendPool
andVideoHttpSettings
. - Path:
/videos/*
- Path type: Prefix
Important: The priority of rules matters. Rules with higher priority (e.g., 3) are evaluated before rules with lower priority (e.g., 1). Ensure your most specific rules have higher priorities.
- Rule Name:
-
Save Configuration
Review your settings and save the Application Gateway configuration.
Testing Your Configuration
Once the deployment is complete, test your URL routing:
- Navigate to
http://your-app-gateway-public-ip/images/logo.png
. This should be served by theImageBackendPool
. - Navigate to
http://your-app-gateway-public-ip/videos/sample.mp4
. This should be served by theVideoBackendPool
. - Navigate to
http://your-app-gateway-public-ip/about
or any other path. This should be served by theDefaultBackendPool
.
Considerations:
- Path Type: Choose between Exact and Prefix path matching based on your needs.
Prefix
is generally more flexible. - HTTPS: For production environments, always configure SSL offloading and use HTTPS listeners.
- Health Probes: Ensure you have appropriate health probes configured for each backend pool to monitor the health of your backend servers.
- Rule Priority: Carefully manage rule priorities to avoid unexpected routing behavior.
Next Steps
Explore other advanced routing scenarios with Application Gateway, such as host-based routing or integration with Azure Web Application Firewall.