How to customize routing and URLs on Ghost
Ghost allows you to customize routing and URLs through the routes.yaml file, which controls how your content is structured and accessed. You can modify permalinks, create custom collections, and set up redirects to match your specific site architecture needs.
Prerequisites
- Admin access to Ghost dashboard
- Basic understanding of YAML syntax
- FTP or file manager access to Ghost installation
Step-by-Step Instructions
Access the Routes Configuration
Understand Routes.yaml Structure
routes:- Custom route mappingscollections:- Post collections with custom URLstaxonomies:- Tag and author page structures
Customize Post Collection URLs
collections:
/blog/:
permalink: /blog/{slug}/
template: index
filter: tag:-hash-hiddenThis creates a /blog/ collection with posts accessible at /blog/post-name/. You can use variables like {slug}, {year}, {month}, and {day}.Create Custom Routes
routes:
/custom-page/:
template: custom-page
/portfolio/:
template: portfolio
data: page.portfolioThe template property specifies which Handlebars template file to use, and data can inject specific content.Configure Taxonomy URLs
taxonomies:
tag: /topic/{slug}/
author: /writers/{slug}/This changes tag pages from /tag/example/ to /topic/example/ and author pages to /writers/author-name/.Set Up Redirects
routes:
/old-page/:
template: index
redirect: '/new-page/'
/legacy-blog/:
redirect: '/blog/'Use 301 redirects for permanent moves to preserve SEO value.Upload and Test Configuration
Verify URL Changes
- Visiting updated collection pages
- Checking individual post URLs
- Testing custom routes and redirects
- Verifying tag and author page URLs
Common Issues & Troubleshooting
YAML syntax error prevents upload
Check for proper indentation using 2 spaces (not tabs) and ensure colons have spaces after them. Use a YAML validator to identify syntax issues.
Custom routes return 404 errors
Verify that the specified template files exist in your active theme's directory. Template names must match exactly, including file extensions.
Redirects not working properly
Ensure redirect URLs start with / for internal redirects or include http:///https:// for external redirects. Check for conflicting routes.
Collection filters not displaying expected posts
Review your filter syntax - use tag:example to include posts with a tag, tag:-example to exclude them. Combine filters with + (AND) or , (OR).