I am generating static pages from nuxt on netlify. We have the structure of url without trailing slashes. For SSR we had trailingslash option set to false and custom redirect with redirect module. But for ‘nuxt generate’ option this is no longer working
I can’t seem to setup 301 redirects for url’s ending with trailing slash.
Ok thanks for the answer. The problem with _redirects is that you’re not allowed to use regex there - so imagine we got over 100 pages and we deploy multiple of them everyday . This way we will have to add manually every single redirection.
I understand the frustration here and I can sympathise! There isn’t a clean and preferred way of achieving this. Every framework, person, will handle trailing slashes a little differently.
We have an open feature request for exactly this – allowing you to decide whether to opt in or out of trailing slashes – and I’ve added this conversation to the request list. Though, I can’t promise if/when this is delivered.
There are some methods of achieving this though they’re not very intelligent (such as this).
@miteyema & @arekk - According to the docs, you can’t use redirects to add or remove trailing slashes:
You’re better of using their pretty URL optimization feature.
I found this to be a super confusing issue, I personally banged my head against the wall trying to implement certain URLs on my site without trailing slashes for SEO purposes as well.
I did this by initially setting the Nuxt router settings to trailingSlash: false, but failed once I realized Netlify tends to add trailing slashes for a lot of URLs, so I regenerated my sitemap and routes, as well as links on the site to all have trailing slashes
TLDR: just use trailing slashes and Netlify’s pretty URL optimization feature, it’ll make your life a lot easier when you’re using Nuxt and Netlify.
Pretty annoying that Netlify imposes this limitation. Why aren’t we able to choose how our own site’s URLs are structured? There are SEO implications. I will have to go try other providers now. For anyone who gives in to Netlify’s limitations and just uses the slash URLs, make sure you also set your canonical tags to point to the slash variants as well.
Update: I just ran a deploy on Vercel (another provider similar to Netlify)… it turns out they do not impose this limitation! Moving my site over there now. Goodbye trailing slashes
Perfect, thanks! It took a few minutes for the changes to propagate, but it definitely worked. And yes, the asset optimization is quite a bizarre UX choice (mistake?).
@Scott, +1 for the option to remove trailing slashes. Is there a place we can vote on potential features?