next-runtime icon indicating copy to clipboard operation
next-runtime copied to clipboard

[Bug]: Pages are not redirected to url with trailing slash

Open vpreponen opened this issue 3 years ago • 5 comments

Steps to reproduce

  1. Go to https://nifty-neumann-ecf646.netlify.app/arkisto
  2. Page is not redirected to https://nifty-neumann-ecf646.netlify.app/arkisto/

If I run yarn build && yarn export in local the files are created as arkisto/index.html. On Netlify it looks like they are created as arkisto.html.

A link to a reproduction repository

https://github.com/vpreponen/indyville/

Plugin version

4.0.0

More information about your build

  • [ ] I am building using the CLI
  • [X] I am building using file-based configuration (netlify.toml)

What OS are you using?

No response

Your netlify.toml file

`netlify.toml`
[[redirects]]
  from = "/feed"
  to = "/feed.xml"
  status = 301
  force = true

[[redirects]]
  from = "/baari"
  to = "https://baari.indyville.fi/"
  status = 301
  force = true

[[redirects]]
  from = "/baari/*"
  to = "https://baari.indyville.fi/:splat"
  status = 301
  force = true

[[redirects]]
  from = "/retro"
  to = "https://retro.indyville.fi/"
  status = 301
  force = true

[[redirects]]
  from = "/retro/*"
  to = "https://retro.indyville.fi/:splat"
  status = 301
  force = true

[[redirects]]
  from = "/kuvat/*"
  to = "https://assets.indyville.fi/kuvat/:splat"
  status = 301
  force = true

[[redirects]]
  from = "/jw_flv/*"
  to = "https://assets.indyville.fi/video/:splat"
  status = 301
  force = true

[[redirects]]
  from = "/svg/*"
  to = "https://assets.indyville.fi/svg/:splat"
  status = 301
  force = true

[[redirects]]
  from = "/tiedostot/*"
  to = "https://assets.indyville.fi/tiedostot/:splat"
  status = 301
  force = true

[[redirects]]
  from = "/villen_muut_tiedostot/*"
  to = "https://vp.indyville.fi/files/:splat"
  status = 301
  force = true

[[redirects]]
  from = "/metsapuhuu/*"
  to = "https://vp.indyville.fi/metsapuhuu/:splat"
  status = 301
  force = true

Relevant log output (or link to your logs)

Build logs

https://app.netlify.com/sites/nifty-neumann-ecf646/deploys/61b9c66dc562b20008e09ff6

vpreponen avatar Dec 15 '21 11:12 vpreponen

Hello! Thanks for raising up this issue.

Trailing slash is not enabled by default by Next, so you'll have to enable it in the config. Instructions on how to do so can be found in the Next Docs.

I also noticed you have two next plugins installed, you can remove netlify-plugin-cache-nextjs which is an older version. One other thing, we do not do any building with next export on the Netlify side, which exports your Next.js application to static HTML.

Let me know if that works for you!

tiffafoo avatar Dec 15 '21 12:12 tiffafoo

Trailing slash is enabled in the config and this works for urls that don't match to static files.

I previously tested removing the cache plugin but this throws a warning during deploy and doesn't fix the redirects.

warn - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache

vpreponen avatar Dec 15 '21 12:12 vpreponen

Ahh, got it, thanks for the extra info. Sadly there doesn't seem to be a great workaround to this yet. Changing your site to not use the CDN via an environment variable (SERVE_STATIC_FILES_FROM_ORIGIN) to make it serve from the origin instead should resolve this for you, but that is at the cost of some performance.

tiffafoo avatar Dec 15 '21 15:12 tiffafoo

All right, thanks for the help. I'll have to change my relative urls to root relative then.

vpreponen avatar Dec 15 '21 19:12 vpreponen

https://github.com/netlify/netlify-plugin-nextjs/issues/1448

MarcL avatar Jul 05 '22 14:07 MarcL

The team at Netlify have now released the new v5 Next.js runtime which has support for both pages and app router, on-demand and time-based revalidation, automatic fine-grained cache control, and automatic image optimization using Netlify's image CDN. This should also fix this issue.

You can find the documentation and additional information here: Next.js on Netlify

The v4 runtime is now in the maintenance support phase with no new features being added. Occasional bug fixes and security patches will be applied when needed.

Thanks!

MarcL avatar Apr 19 '24 13:04 MarcL