REWRITE_MATCH_PATTERN / REWRITE_SUBSTITUTION Feature #557
-
Hello Guys ! Can someone help me with the REWRITE_MATCH_PATTERN / REWRITE_SUBSTITUTION feature ?, its the first time that i'm using this solution and I need to rewrite the path to automate the resize and image convertion, so right now my image is *.jpg and I need to resize to 200x200 and convert to webp. In my lab i have this situation: https://drbcl8n949yxk.cloudfront.net/ilha-grande.jpg and i need something like this: https://drbcl8n949yxk.cloudfront.net/fit-in/200x200/filters:format(webp)/ilha-grande.jpg Manualy it works fine using the browser. I probably misunderstood how to use. Reading the documentation (https://docs.aws.amazon.com/solutions/latest/serverless-image-handler/use-the-rewrite-feature.html) I understood that we have to use regex, locking to the URI path, but it didn't work. I tried these 2 models, but apparently neither worked, "REWRITE_MATCH_PATTERN": '^https?://[a-zA-Z0-9-.]+.[a-zA-Z]{2,}(?:/[\w-./])(?:.jpg|.jpeg|.png|.gif)?$' "REWRITE_MATCH_PATTERN": "^/[a-zA-Z0-9-./]*.jpg$", Thanks in advance !! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @espietrobom, You're pretty close with your solutions. In the first solution, we aren't hitting the match since the CloudFront URL isn't included when testing the match. In the second solution, it doesn't look like you're capturing any match groups, so rebuilding the path in the substitutions has nothing to build from. For this particular problem, I had success with the following values: REWRITE_MATCH_PATTER: This will match any path that ends in .jpg and will append that matched value to Let me know if you run into any issues, |
Beta Was this translation helpful? Give feedback.
Hi @espietrobom,
You're pretty close with your solutions. In the first solution, we aren't hitting the match since the CloudFront URL isn't included when testing the match. In the second solution, it doesn't look like you're capturing any match groups, so rebuilding the path in the substitutions has nothing to build from.
For this particular problem, I had success with the following values:
REWRITE_MATCH_PATTER:
/^(.+\.jpg)$/gm
REWRITE_SUBSTITUTION:
/200x200/filters:format(webp)/$1
This will match any path that ends in .jpg and will append that matched value to
/200x200/filters:format(webp)/
Let me know if you run into any issues,
Simon