Pretty urls return 404 on /about instead of 301 to /about/

Heya!

I was wondering if somebody can clarify pretty_urls for me.

I’ve expected 301-redirect from /about to /about/, but getting a 404 instead.

demo: https://pretty404.netlify.app/about/

Here is my repo. I am on Astro, server side, using Netlify adapter and netlify.toml with pretty_urls set to ‘true’. My trailingSlash set to ‘always’ and files’ format to ‘directory’.

Am I missing something and this part of the Scott’s guide is not applicable to my case?

Should I configure 301 myself? (I’ve read that it is better to rely on pretty_urls to handle trailing slashes)

Stuff I’ve read before asking:

  1. Docs
  2. Forum
  3. [Support Guide] How can I alter trailing slash behaviour in my URLs? Will enabling Pretty URLs help?
  4. Pretty URLs, URL Routing, and Trailing-Slashes

@my-astro As I understand it the pretty_urls functionality is for standard static sites.

A file of /about/index.html results in /about/
A file of /about.html results in /about

If using a more complex system like Astro, you would need to learn how Astro achieves what you want.

It’s highly likely your requests are handled by a function, and Netlify’s system isn’t even playing a part.

For example these definitely aren’t ‘static files’ for your site:
https://pretty404.netlify.app/about.html
https://pretty404.netlify.app/about/index.html

I can’t give you specifics as I don’t work with Astro, but you probably want to re-read something like:
https://docs.astro.build/en/guides/routing/

Hi there!
Thank you for your reply!

So, Netlify does not normalize URLs of server side projects?

My astro format configured as “directory”, meaning this /about/index.html outputs /about/ page on build.

I am using folders structure to comply with Netlify’s general approach to trailing slashes. I also did not want to configure 301 redirects myself, since it will create infinite loops of redirects when Netlfy’s URL normalization will kick in. (According to the Netlify’s Docs)

Could someone bring light to my issue, please:

  • Does Netlify normalize URLs for server-side projects?
  • Does pretty_urls configuration work for server-side websites?

@my-astro I can’t say for certain, as I don’t work with “server side projects” with Netlify.

You can wait for Netlify to answer, if you need to confirm more quickly you could check/test yourself.

Step 1.
Confirm what files your build is producing.
You can do this by running your build locally, or using the Deploy File Browser:
https://answers.netlify.com/t/new-feature-browse-files-in-your-deploy-with-the-deploy-file-browser/105196

Determine if you’re using “server side functionality” or only static files.

Step 2A (Static Site)
If you are using only static files.
Then it should be operating as per the Netlify documentation.

Step 2B (‘Functions’ Based Site)
If you’re using “server side functionality”
You could deploy a static minimum reproduction of the structure to see if it behaves differently.

If you haven’t seen it already, Netlify’s documentation for ‘Astro on Netlify’ is here:
https://docs.netlify.com/frameworks/astro/

Depending on your project, you may also be dealing with the behavior of Astro’s ‘Netlify Adapter’:
https://docs.astro.build/en/guides/deploy/netlify/
https://docs.astro.build/en/guides/integrations-guide/netlify/

Step 1 result
Deploy file browser contains 2 files:

  • favicon.svg
  • netlify.toml

Step 2A (Static Site)
Deploy file browser contains 4 files:

  • about/index.html
  • favicon.svg
  • index.html
  • netlify.toml

demo: https://prettystatic.netlify.app/about/
repo: GitHub - my-astro/prettystatic

I’ve tested pretty_urls on a static variant and it works as expected: both /about.html and /about redirect to /about/.

So now we know on practice, that pretty_urls work on static websites and do not apply to Astro SSR (output: ‘server’). For people who will search for such topic – I first thought that this thread is unrelated, but seems it is since Astro Netlify adapter is a function.

The thing I want to clarify is URLs normalization, I can’t wrap my head over it and if you have any ideas how can I test if normalization kicks in will be much appreciated!

Normalization does not apply to Functions as users would expect the URLs to be “as-is” so they can perform any required actions with the URLs themselves.