Configuration reference
This is the Traffic Policy configuration reference for this action.Supported phases
on_http_request
Type
url-rewrite
Configuration fields
Behavior
This action replaces all occurrences of thefrom regular expression in the request URL with the to replacement value.
Matching
Matching is performed against the entire URL, including the scheme, userinfo, host, and port, not just the path. To match requests that begin with/products, use CEL Interpolation and write ^${req.url.authority}/products, or use an expression like req.url.path.startsWith('/products') in the phase rule’s expressions field.
Note about CEL interpolation
All CEL Interpolation will occur before regular expressions are evaluated.Non-terminating action
This is a Non-terminating action. It does not return a response, and will allow Traffic Policy processing to continue to the next Action in the chain. All Cloud Endpoint Traffic Policies must end with a terminating action. This requirement does not apply to Agent Endpoints.Examples
Rewrite using paths
The following Traffic Policy configuration demonstrates how to use theurl-rewrite action to transparently
rewrite the request URL from /products to /products.php.
Example Traffic Policy document
/products to /products.php
without changing the URL seen by the client. This is useful for hiding away
the underlying implementation details of your service.
Example request
Example server logs
Conclusion
In this example, a request to/products is internally
routed to /products.php, and the response is served
from products.php while the client remains unaware
of the URL rewrite.
Rewrite using regular expressions
The following Traffic Policy configuration demonstrates how to use theurl-rewrite action to transparently
rewrite the request URL from /products/* to /products.php.
Example Traffic Policy document
/products/* to
/products.php?query=$1 without changing the URL seen by the client. This is
useful for hiding away the underlying implementation details of your service.
Example request
Example server logs
Conclusion
In this example, a request to/products is internally routed to
/products.php?query=123, and the response is served from products.php while
the client remains unaware of the URL rewrite.
Rewrite using CEL interpolation
The following Traffic Policy configuration demonstrates how to use theurl-rewrite action to transparently
rewrite the request URL from /products/* to /products.php using a global
policy rule (no expression) by leveraging CEL Interpolation.
Example Traffic Policy document
/products/*
to /products.php?query=$1 without changing the URL seen by the client. It does
this by leveraging CEL Interpolation to replace the
from value with the request URL authority. This is useful for hiding away the
underlying implementation details of your service.
Example request
Example server logs
Conclusion
In this example, a request to/products is internally routed to
/products.php?query=123, and the response is served from products.php while
the client remains unaware of the URL rewrite.