Working with Hugo, a popular static site generator, sometimes requires adjusting post URLs. Whether it’s a typo, a need for better SEO, or content reorganization, changing a URL can be tricky. This guide will walk you through the process of modifying your post’s URL while maintaining your site’s search engine optimization (SEO) and existing link integrity.

Why Change a Post URL?

Common reasons for changing a post URL include:

Step-by-Step URL Modification Process

1. Update the Post’s Front Matter

In your Hugo post’s front matter, modify the url parameter to reflect the desired URL:

# Before (with typo)
url: /blog-post-wit-errors/

# After (corrected)
url: /blog-post-with-corrections/

2. Create an Alias for the Old URL

To preserve SEO value and prevent broken links, use the aliases parameter:

title: "Improving Blog Post URLs"
type: post
url: /blog-post-with-corrections/
aliases: ['/blog-post-wit-errors/']

How Aliases Work

When you create an alias, Hugo generates a separate HTML page at the old URL location. This page contains a meta redirect tag that automatically sends visitors (and search engine crawlers) to the new URL. This approach ensures:

Best Practices

  1. Minimize URL Changes: Only change URLs when absolutely necessary.
  2. Update Internal Links: Check and update any internal links pointing to the old URL.
  3. Use 301 Redirects: Hugo’s alias system effectively creates 301 (permanent) redirects.
  4. Inform Search Engines: If possible, use Google Search Console to indicate the URL change.

Potential Pitfalls to Avoid

Example Scenario

Let’s look at a practical example:

# Original post with a typo
title: "Web Development Insights"
url: /web-devlopment-tips/

# Corrected post
title: "Web Development Insights"
url: /web-development-tips/
aliases: ['/web-devlopment-tips/']

Conclusion

Changing URLs in Hugo doesn’t have to be complicated. By using the aliases parameter, you can seamlessly update your post URLs while maintaining SEO performance and user experience.

Pro Tip: Always test your URL changes thoroughly, checking both the old and new links to ensure smooth redirection.