On this page
Ghost keeps its redirects in one file, redirects.yaml. Each rule sends an old path to a new one, or to another website. Readers, newsletters and search engines hold links to exact URLs, so when you rename a post, move from another platform or change your permalinks, redirects keep those links working.
Redirects don’t decide your URL structure: that’s routing, in routes.yaml. They bridge old URLs to the new ones after you change it. Ghost’s implementing redirects (opens in a new tab) tutorial is the full reference.
301 or 302
| Code | What it says | Use it for |
|---|---|---|
| 301 | Moved for good. Search engines move the old URL’s ranking to the new one. | Renamed slugs, migrations from WordPress, Medium or Substack, merged duplicate URLs, moving /articles/ to /blog/ |
| 302 | Moved for now. The old URL is expected back. | Short maintenance moves, campaigns, anything you plan to revert |
When in doubt, and after every migration, use 301.
Where to edit redirects.yaml
In Ghost Admin, go to Settings › Advanced › Labs › Beta features. The Redirects row has an Edit button to change the file in the browser, and a menu to Download file and Upload file if you’d rather edit it in a code editor.
Ghost checks the whole file when you save or upload it. If one rule is invalid, such as a broken regular expression, it rejects the file and your current redirects stay as they are. A new site starts with no redirects.
Older sites may still have their redirects as JSON; Ghost reads that too, but write new rules in YAML.
The file format
The file has two keys, 301 and 302. Under each, list source: destination pairs. For pages on your own site, write only the path, without the domain:
301:
/old-post-slug/: /new-post-slug/
/another-from/: /another-to/
302:
/temporary-source/: /temporary-destination/Indent with spaces, never tabs. Ghost URLs end with a slash, so write your rules the same way, and test both with and without the slash if a rule doesn’t fire.
To remove every redirect, save the file with both keys and no rules under them:
301:
302:Simple redirects
One post renamed:
301:
/old-slug/: /new-slug/A tag renamed, or tag URLs changed in routes.yaml:
301:
/tag/old-label/: /tag/new-label/To another website, with the full URL:
301:
/legacy-page/: https://example.com/docs/new-location/Several old URLs to one:
301:
/editing-a-post/: /editing/
/editing-posts/: /editing/Regex redirects
A plain path matches one URL. A regular expression matches many at once, which is what you need after a migration or a permalink change. Ghost uses JavaScript regular expressions. In the destination, $1, $2 and so on insert what the groups in brackets captured.
Warning
A wrong pattern can cause redirect loops, mass 404s or redirects you didn’t mean. Test each pattern on regex101 (opens in a new tab) with the ECMAScript (JavaScript) flavor, add one rule at a time, and try it on a staging site first if you have one.
Remove a path prefix
Your old site had posts at /blog/post-slug/; Ghost has them at /post-slug/:
301:
^\/blog\/([a-z0-9-]+)\/$: /$1/The group captures the slug after /blog/, and the visitor goes to /{slug}/. Change [a-z0-9-]+ if your slugs have other characters.
WordPress dated URLs
Year, month and day in the path (/2020/03/15/my-post/ → /my-post/):
301:
^\/[0-9]{4}\/[0-9]{2}\/[0-9]{2}\/(.*): /$1Year and month only (/2020/03/my-post/ → /my-post/):
301:
^\/[0-9]{4}\/[0-9]{2}\/(.*): /$1These work only when the Ghost slug is the same as the old one. Where the importer changed slugs, add a plain rule for each of those posts.
Categories to tags
Imports usually turn categories into tags:
301:
^\/category\/(.*): /tag/$1A whole section
Redirects match URL paths, not collection names. If your posts moved from /articles/ to /blog/ with the same slugs:
301:
^\/articles\/(.*)$: /blog/$1Or from /articles/my-post/ to the root, /my-post/:
301:
^\/articles\/(.*)$: /$1Put specific rules above broad patterns, and use plain rules before you reach for one large regex.
From other platforms
Squarespace’s /blog/ prefix to a root slug:
301:
^\/blog\/(\S+): /$1Medium adds an ID to the end of each slug. This strips it; check it against your real URLs first:
301:
^\/(?!p\/)(.*)(-[0-9a-f]{10,12}): /$1Substack uses /p/ for posts, and Ghost uses /p/ for post previews, so these need care: start from the Substack example in Ghost’s implementing redirects (opens in a new tab) tutorial.
When not to use redirects
- HTTPS and
www: set these at your DNS, host or reverse proxy (such as Caddy or nginx), not inredirects.yaml. - Trailing slashes: Ghost already adds them; you don’t need rules for that.
- Designing your URLs: use
routes.yamlfor/blog/, collections and taxonomies, and redirects only for the old URLs left behind. - A new domain: that’s DNS and your Ghost config; see how to change your domain in self-hosted Ghost.
Redirects after a routing change
A change to collections or permalinks in routes.yaml changes post URLs at once, and every existing link still points to the old ones. After you change your routing:
- List the old URLs: from your old platform’s export, your analytics or Google Search Console.
- Add 301 rules from the old paths to the new ones.
- Save the file and test the old URLs.
For example, if you moved the post list from / to /blog/ and your posts’ permalink became /blog/{slug}/, the old /my-post/ needs a rule to /blog/my-post/. A custom homepage is the usual reason for that change.
Test your redirects
- Open an old URL in a private window, so your browser cache doesn’t hide the result.
- Check the response with
curl -I https://yoursite.com/old-path/: you should see301(or302) and the new URL in thelocationheader. - Spot-check the URLs that get the most visits or links.
If a rule doesn’t work:
- Slash mismatch: the source or destination lacks the trailing slash your URLs use.
- Pattern too broad:
(.*)matches more than you meant. Narrow it, and anchor it with^and$. - Two rules for one path: remove one and test again.
- CDN cache: an edge cache can serve the old response for a while after you save.
Changing where posts appear rather than where they redirect? That’s a collection filter: see filter expressions in Ghost.