Skip to main content

Customizing Request Routing with URL Rewriting

URL rewriting allows you to modify request URLs before forwarding them to your upstream service. This includes changing the hostname, path, or query parameters to ensure that requests are correctly formatted before reaching their destination.

By rewriting URLs at the network edge, you can:

🔄 Standardize API request formats across different backends.
🚀 Ensure compatibility between clients and services.
⚡ Optimize backend routing without requiring changes to application code.

🔍 What are the Benefits of URL Rewriting?​

URL rewriting is an essential feature for API gateways, load balancers, and proxy servers, allowing for seamless request transformation before traffic reaches the backend.

Key Benefits:

  • Enable Backward Compatibility: Allow older clients to use new API paths without breaking compatibility.
  • Simplify Microservices Routing: Adjust URLs dynamically when forwarding requests to multiple backend services.
  • Support Multi-Tenant Architectures: Rewrite hostnames or paths based on tenant information.
  • Improve API Gateway Interoperability: Ensure requests are formatted correctly for third-party APIs and microservices.
  • Path Normalization: Standardize incoming requests (/v1/users → /api/users).
  • Hostname Rewriting: Change hostnames (old.example.com → new.example.com).
  • Backend Service Path Adjustments: Route requests to different paths without requiring frontend changes.

Rewrite Full Path​

The following examples showcase how to create an endpoint that rewrites requests. The hostname, scheme, and port are kept the same, but the entire path of the request is changed.

  • Requests to https://example-hostname.ngrok.io/example will be rewritten to https://example-hostname.ngrok.io/rewrite
  • Requests to https://example-hostname.ngrok.io/example/foo will be rewritten to https://example-hostname.ngrok.io/rewrite

Check out the URL rewrite traffic policy action page for more details about how it functions and the parameters it accepts.

Loading…

Rewrite Path Prefix​

The following examples showcase how to create an endpoint that rewrites requests. The hostname, scheme, and port are kept the same, but only the prefix is changed.

  • Requests to https://example-hostname.ngrok.io/example will be rewritten to https://example-hostname.ngrok.io/rewrite
  • Requests to https://example-hostname.ngrok.io/example/foo will be rewritten to https://example-hostname.ngrok.io/rewrite/foo

Check out the URL rewrite traffic policy action page for more details about how it functions and the parameters it accepts.

Loading…

Rewrite Port​

The following examples showcase how to create an endpoint that rewrites requests. The hostname, scheme, and path are kept the same, but only the port is changed.

  • Requests to https://example-hostname.ngrok.io:8080 will be rewritten to https://example-hostname.ngrok.io:9000

Check out the URL rewrite traffic policy action page for more details about how it functions and the parameters it accepts.

Loading…

Rewrite Hostname​

The following examples showcase how to create an endpoint that rewrites requests. The scheme, port, and path are kept the same, but only the hostname is changed.

  • Requests to https://example-hostname.ngrok.io will be rewritten to https://other-example-hostname.ngrok.io

Check out the URL rewrite traffic policy action page for more details about how it functions and the parameters it accepts.

Loading…