nginx

Nginx rewrite and change timestamp format


Is it possible to change the timestamp format of a rewrite URL in Nginx?

Example:

https://test.mysite.com/content/07-06-2024T12:41/https://www...etc

to a %Y-%m-%d%H:%M:%S format?

Like:

https://test.mysite.com/content/2024-06-07T12:41:51Z/https://www...etc

Solution

  • I was able to do this with:

    "~^/content/(\d{2})-(\d{2})-(\d{4})T(\d{2}):(\d{2})/(?<requestedUrl>.)$"
    

    Which directs with:

    https://test.mynewsite.com/browse/$redacted?timestamp=$4-$3-$2T$5:$6:59Z&url=$requestedUrl;