Rewrite blog archive URLs

Create a transform rule to rewrite the URL format /posts/<YYYY>-<MM>-<DD>-<TITLE> to the new format /posts/<YYYY>/<MM>/<DD>/<TITLE>.

Last updated Oct 13, 2025 To rewrite the URLs of a blog archive that follow the URL format /posts/<YYYY>-<MM>-<DD>-<TITLE> to the new format /posts/<YYYY>/<MM>/<DD>/<TITLE>, create the following URL rewrite rule:

Text in Expression Editor:

http.request.uri.path ~ "^/posts/[0-9]+-[0-9]+-[0-9]+-.*"

Text after Path > Rewrite to > Dynamic:

regex_replace(http.request.uri.path, "^/posts/([0-9]+)-([0-9]+)-([0-9]+)-(.*)$", "/posts/${1}/${2}/${3}/${4}")

The function regex_replace() also allows you to extract parts of the URL using regular expressions' capture groups. Create capture groups by putting part of the regular expression in parentheses. Then, reference a capture group using ${<NUMBER>} in the replacement string, where <NUMBER> is the number of the capture group.

Was this helpful?

YesNo

On this page

Rewrite blog archive URLs - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/rules/transform/examples/rewrite-archive-urls-new-format/#page","headline":"Rewrite blog archive URLs","description":"Create a transform rule to rewrite the URL format /posts/\u003cYYYY>-\u003cMM>-\u003cDD>-\u003cTITLE> to the new format /posts/\u003cYYYY>/\u003cMM>/\u003cDD>/\u003cTITLE>.","url":"https://developers.cloudflare.com/rules/transform/examples/rewrite-archive-urls-new-format/","inLanguage":"en","image":"https://developers.cloudflare.com/rules/transform/examples/rewrite-archive-urls-new-format/og.png?v=6ae81122ce561809","dateModified":"2025-10-13","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"},"keywords":["URL rewrite"]}


description: Create a URL rewrite rule (part of Transform Rules) to rewrite everything under /blog/<PATH> to /marketing/<PATH>. title: Rewrite path of moved section of a website image: https://developers.cloudflare.com/rules/transform/examples/rewrite-moved-section/og.png?v=aa177a6675f50a0d


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/rules/llms.txt
Use this file to discover all available pages before exploring further.