Urls, redirects, and the trailing slash

What is the name of the domain?

What is the issue you’re encountering

Just wondering why my domain sub1.io/ navigates to sub1.io (but not a redirect status code), but sub1.io/datacentres redirects to sub1.io/datacentres/.

**Edit: what’s with the single input element to type a question?

A path separator when there is no path in the URL is removed by your browser because it’s meaningless. The URL specification says:

A path-absolute-URL string must be U+002F (/) followed by a path-relative-URL string.

So that slash isn’t seen as part of the path even though the path you’re requesting is / in the Unix sense. This seems odd but is probably just so that slash is always optional, making the syntax easier.

Enforcement of the trailing slash on paths is opinionated behavior of Cloudflare Pages.

1 Like

ah that explains why there’s no redirect either, thanks a lot!

Actually, is it possible to align my site structure with that opinionated behaviour? ie so that it puts the trailing slash removing the need for the redirect?

Just make sure your links include the trailing slash. You don’t need to change your site structure, just the links themselves.

But isn’t it Astro that’s creating the pages?

I’m just confused because SEMRush is reporting a redirect from the non-trailing slash page to the trailing slash page. And having the inclusion of trailing slashes in any links fix that would feel like magic :smiley:

Right now, you have a link to /datacentres, which Pages then redirects to /datacentres/.

If you change that link to point to /datacentres/ then there won’t be a redirect because it’s already pointing to the trailing-slash version.

I’m not real familiar with how Astro handles links. But, I think you want build.format set to directory, and probably also trailingSlash set to always.

2 Likes

Amazing help mate, really appreciate it!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.