Fastly vcl for 301 redirecting mixed case paths to lowercase

1.1k views Asked by At

Since a migration, my app has mixed case paths that are still linked to, but these should 301 redirect to all lowercase paths. However there are some paths that need to still exist as mixed case for legacy api and graphql query reasons.

A more detailed, but still simplified version of my question is: using custom vcl in my Fastly configuration, how can I 301 redirect all mixed case urls to lowercase, but exclude /api and /graphql? I think I also want to exempt all query strings and hashes from being lowercased.

My familiarity with vcl is pretty minimal, would definitely appreciate some examples!

UPDATE: So far I have the following, but I don't have a lot of confidence in it, yet:

if (req.url.path !~ "^/(api|graphql)" && req.url.path ~ "^/([A-Z])") {
  set req.url.path = std.tolower(req.url.path);
  set resp.status = 301;
}
1

There are 1 answers

0
Omar Soufiane On

graphql is basically post requests divided into mutation/ queries, and fastly or varnish caches get requests