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:

Scenario Overview

We will configure Application Gateway to route traffic as follows:

Diagram showing Application Gateway routing based on URL paths
Conceptual diagram of URL-based routing

Steps to Configure URL Routing

  1. 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.
  2. 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).
  3. 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
  4. 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 and DefaultHttpSettings.
    • Path-based routing: Select Yes.
    • Add path: Click Add path.
    • Backend target: Select DefaultBackendPool and DefaultHttpSettings.
    • 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 and ImageHttpSettings.
    • Path-based routing: Select Yes.
    • Add path: Click Add path.
    • Backend target: Select ImageBackendPool and ImageHttpSettings.
    • Path: /images/*
    • Path type: Prefix

    Rule 3: Video Rule

    • Rule Name: VideoRule
    • Priority: 3
    • Listener: appgw-listener
    • Backend target: Select VideoBackendPool and VideoHttpSettings.
    • Path-based routing: Select Yes.
    • Add path: Click Add path.
    • Backend target: Select VideoBackendPool and VideoHttpSettings.
    • 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.

  5. Save Configuration

    Review your settings and save the Application Gateway configuration.

Testing Your Configuration

Once the deployment is complete, test your URL routing:

Considerations:

Next Steps

Explore other advanced routing scenarios with Application Gateway, such as host-based routing or integration with Azure Web Application Firewall.