Github iconEdit on Github
This version of the Cloudflare Workers documentation is deprecated. Visit the new documentation

Conditionally Changing a URL

To conditionally change a URL based on the domain, your Worker code will look something like this:

With VCL:

if ( ~ "^restricted") {
  set req.url = "/sanitized" req.url;

With Workers:

let url = new URL(request.url);
if (url.hostname.startsWith("restricted")) {
  url.pathname = "/sanitized" + url.pathname;