URL Normalization for Astro Sites: Why and How to Always Enable Trailing Slash
I’ve implemented a configuration to always enable trailing slash for URL normalization on this site, CodeNote.net.
Trailing slash refers to the slash /
at the end of a URL. For example, these two URLs:
https://codenote.net/about/
(with slash)https://codenote.net/about
(without slash)While humans see them as the same page, search engines may recognize them as separate URLs. As a result, site evaluations like backlinks may be distributed between two URLs, which can be disadvantageous for SEO.
To avoid this problem, it’s recommended to unify (normalize) to one format and set up 301 redirects from the other.
To decide which format to unify to, I referenced several articles:
To summarize Google’s position: “For non-root URLs, either is fine, but it’s important to maintain consistency within the site and normalize.”
Ultimately, CodeNote.net decided to unify with “slash included”.
The reason was that Ahrefs, Zapier and Astro blogs adopt the format with slash, and I thought having an explicit /
would be clearer.
With Astro, this configuration is very simple. Just add the trailingSlash
option as one line to the astro.config.mjs
file.
{
// Example: Require a trailing slash during development
trailingSlash: 'always'
}
With just this configuration, Astro normalizes URLs at build time and properly handles redirects on development servers and production environments.
Normalizing site URLs is a basic but very important SEO measure.
With Astro, you can easily implement this with just one line of configuration: trailingSlash: 'always'
, so if you haven’t configured it yet, please check it out.
That’s all from the Gemba.