In short. A Ghost regex redirect pairs a source pattern with a destination in redirects.yaml, using $1 to reuse the first captured part of the path.
Definition: As of 17 October 2026, a regular expression redirect in Ghost is a
redirects.yamlrule whose source uses a pattern to match URL paths. A capturing group remembers part of the matched path, and$1inserts the first captured part into the destination.
Key facts
- Ghost's redirects documentation places permanent redirects under
301and temporary redirects under302inredirects.yaml. - Ghost's Implementing redirects tutorial uses
^\/blog\/([a-z0-9-]+)\/$as a source and/$1as its destination. - MDN's regular expression syntax cheatsheet defines parentheses as a capturing group and the
+quantifier as matching the preceding item one or more times.
How does the source pattern work?
Ghost's tutorial supplies this complete rule for removing a /blog/ prefix while retaining the post slug, the path component that identifies the post:
301:
^\/blog\/([a-z0-9-]+)\/$: /$1
The source pattern is the YAML key to the left of the colon. The destination follows the colon. The example uses a permanent redirect because the rule sits under 301.
MDN's syntax cheatsheet explains the components. The ^ anchor marks the beginning of the input, and $ marks its end. The escaped slashes match literal slashes. The character class [a-z0-9-] matches a lowercase letter, a digit or a hyphen; + requires at least one such character. Parentheses capture that sequence.
The final \/$ requires a trailing slash at the end of the matched path. The character class excludes slashes, so the captured slug occupies a single path segment. These constraints matter when selecting paths to test against the rule.
How does a captured path become the destination?
Ghost's Implementing redirects tutorial explains that $1 represents the captured match. In the blog example, the group contains the slug after /blog/; the destination /$1 places that slug after a leading slash.
The same tutorial provides a migration example that changes category paths into tag paths:
301:
^\/category\/(.*): /tag/$1
Here, /tag/ is fixed destination text and $1 supplies the captured suffix. MDN's cheatsheet defines . as matching any character except line terminators, and * as allowing zero or more repetitions. Consequently, this suffix pattern can include further slashes and can also be empty. It covers a broader set of suffixes than the blog example's character class.
How is the rule uploaded and checked?
Ghost's redirects documentation gives the Admin location as Settings → Advanced → Labs, then the Beta features tab. The existing redirects.yaml file is downloaded, edited in a code editor and uploaded again. YAML indentation uses spaces.
Ghost's tutorial recommends testing patterns in regex101 with the ECMAScript/JavaScript flavor selected. After upload, the documented check is to visit a redirected URL and confirm the destination in the browser. Testing the pattern and visiting an old path check different parts of this workflow: the matching expression and the uploaded redirect.
Related terms
FAQ
Can I use a temporary redirect with a regular expression?
Ghost's redirects documentation assigns temporary redirects to 302. You can place the rule under that key when the move is temporary.
Why does the blog example use $1?
Ghost's tutorial uses $1 to insert the match captured by the parentheses. You retain the post slug while changing the surrounding path.
Do I need a separate rule to add trailing slashes?
The same Ghost tutorial states that Ghost automatically forces trailing slashes. You can keep the trailing slash in the example's source pattern when checking its matches.
Sources
- Ghost, "Redirects", updated 11 November 2024
- Ghost, "Implementing redirects", updated 22 April 2026
- MDN Web Docs, "Regular expression syntax cheatsheet", updated 27 August 2026
Check how a page reads to answer engines. Open the GEO score analyzer