Skip to content

Request Rewrite Use Cases#

This tutorial covers common use cases for the Request Rewrite phase in Peakhour.IO.

1. Normalise URLs to Lowercase#

This filter converts the request URI path to lowercase:

http.request.uri.set:
  path: ${lower(http.request.uri.path)}

The configuration sets the path of the request URI to its lowercase version.

2. Add a Query Parameter#

This filter adds a query parameter to all requests:

http.request.uri.set:
  path: ${http.request.uri.path}
  query: ${concat(http.request.uri.query, "&source=cdn")}

The configuration sets the query of the request URI by concatenating the existing query with "&source=cdn".

3. Rewrite Legacy URLs#

This filter identifies requests to old product URLs:

starts_with(http.request.uri.path, "/old-products/")

The configuration rewrites the path for these requests:

http.request.uri.set:
  path: ${concat("/new-products/", http.request.uri.path.slice(14))}

4. Remove Trailing Slashes#

This filter identifies URLs ending with a slash:

http.request.uri.path ends_with "/":

The configuration removes the trailing slash:

http.request.uri.set:
  path: ${http.request.uri.path.slice(0, -1)}

These examples demonstrate how to use the Request Rewrite phase to modify incoming requests before they are processed by subsequent phases.