Gatsby: How to completely remove trailing slashes

Created on 7 May 2019  路  4Comments  路  Source: gatsbyjs/gatsby

I desperately need to NOT generate any trailing slashes for Gatsby pages.

I'm currently using gatsby-plugin-remove-trailing-slashes but the plugin seems to give me more problems than it solves:

  • it doesn't work when JS is disabled (my site works great also with JS disabled and I don't want any trailing slashes for the SSRendered pages when JS is disabled - good for crawler bots!)
  • the plugin adds ugly 301 redirects instead of sanitizing urls and I'm getting enormous amounts of warnings in Google Webmaster Tools about the redirects. Something I want to avoid at all cost.

Anyone could tell me how to force Gatsby to NOT generate any trailing slashes while generating pages?
Thanks

help wanted stale?

Most helpful comment

There's a discussion about this issue going on here: https://github.com/gatsbyjs/gatsby/issues/9207

For my side, I stopped trying to solve it within Gatsby, we handle it on Lambda@Edge instead. If that's something you can do, you can see my comment in the above issue https://github.com/gatsbyjs/gatsby/issues/9207#issuecomment-479359403

All 4 comments

I've found one way to prevent this from happening is to use createPage with a .html extension. This prevents Gatsby from making a folder with an index.html for that page when doing gatsby build. https://www.gatsbyjs.org/docs/actions/#createPage

// Creates /public/my-sweet-new-page/index.html
createPage({ path: '/my-sweet-new-page/' })

// Creates /public/my-sweet-new-page.html
createPage({ path: '/my-sweet-new-page.html' })

(Disclaimer: I'm still investigating this too! There might be better ways than this.)

Nice workaround, however, trailing .html is something I want to avoid also. Any other ideas?

There's a discussion about this issue going on here: https://github.com/gatsbyjs/gatsby/issues/9207

For my side, I stopped trying to solve it within Gatsby, we handle it on Lambda@Edge instead. If that's something you can do, you can see my comment in the above issue https://github.com/gatsbyjs/gatsby/issues/9207#issuecomment-479359403

Hey again!

It鈥檚 been 30 days since anything happened on this issue, so our friendly neighborhood robot (that鈥檚 me!) is going to close it.

Please keep in mind that I鈥檓 only a robot, so if I鈥檝e closed this issue in error, I鈥檓 HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else.

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the Gatsby community!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Oppenheimer1 picture Oppenheimer1  路  3Comments

dustinhorton picture dustinhorton  路  3Comments

KyleAMathews picture KyleAMathews  路  3Comments

signalwerk picture signalwerk  路  3Comments

jimfilippou picture jimfilippou  路  3Comments