Ghost includes support for implementing URL redirects through the use of a custom redirects.yaml
file.
Redirects can be useful for:
- Changing your site URL structure – If you're reorganizing your site's content, or updating your permalink structure, you may need to set up redirects to ensure that any links pointing to old URLs are automatically redirected to the correct new URL. This can help preserve your site's SEO, and ensure that readers are able to find the content they're looking for.
- Updating or removing content – If you have content on your site that is outdated or no longer relevant, you may want to remove it or replace it with new content. In this case, you can set up a redirect to automatically send readers to a new page or post that is related to the old content.
- Fixing broken links – If you have links on your site that are broken, or no longer work, you can set up a redirect to automatically send readers to a working page or post that is related to the broken link.
Ghost supports 301
and 302
redirects. 301
redirects are for permanent redirects, and 302
redirects are for temporary redirects.
To implement redirects, go to the Settings → Advanced → Labs area of Ghost Admin. Open the Labs area using the Open/Close toggle, and select the Beta features tab.
Download your existing redirects.yaml
file.
Once downloaded, open the file in a code editor to add custom redirect rules to the file in YAML format. Be sure to use spaces and not tabs to indent rules.
For example:
301:
/permanent-redirect-from: /permanent-redirect-to
/permanent-redirect-from-2: /permanent-redirect-to-2
302:
/temporary-redirect-from: /temporary-redirect-to
Upload your edited file in the labs area.
For additional information on setting up redirects in Ghost, check out our Implementing Redirects tutorial.