Skip to content

Error when deploying to Netlify because of 301 redirect with trailing slash #1410

Discussion options

You must be logged in to vote

Problem suddenly disappeared. I am still not sure what was causing it, but 301 redirect to same url with trailing slash is no longer happening.
The solution might be to untick this option in Netlify.

I also added this middleware to avoid all trailing slash :
middleware/noTrailingSlash.global.js

import { withoutTrailingSlash } from 'ufo'

export default defineNuxtRouteMiddleware((to) => {
  if (to.path.endsWith('/') && to.path !== '/') {
    return navigateTo(withoutTrailingSlash(to.path, true), { redirectCode: 301 })
  }
})

Thanks @nathanchase for the tip.

✌️

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@notflip
Comment options

Answer selected by benoitdemaegdt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants