gatsby: gatsby-plugin-remove-trailing-slashes not working when using `gatsby develop`

Description

gatsby-plugin-remove-trailing-slashes seems to work when running gatsby serve but not when running gatsby develop

Steps to reproduce

I created a demo project from the CLI to demonstrate the behaviour. https://github.com/itmayziii/gatsby-trailing-slahes-demo screen shot 2019-01-16 at 11 09 28 am

Expected result

Gatsby plugins should work the same in develop as when building the project.

Actual result

gatsby develop is not removing trailing slashes.

What happened.

Environment

System: OS: macOS 10.14.2 CPU: (8) x64 Intel® Core™ i7-7920HQ CPU @ 3.10GHz Shell: 3.2.57 - /bin/bash Binaries: Node: 10.15.0 - /usr/local/bin/node Yarn: 1.12.3 - /usr/local/bin/yarn npm: 6.4.1 - /usr/local/bin/npm Browsers: Chrome: 71.0.3578.98 Firefox: 64.0.2 Safari: 12.0.2 npmPackages: gatsby: ^2.0.76 => 2.0.76 gatsby-image: ^2.0.20 => 2.0.25 gatsby-plugin-manifest: ^2.0.9 => 2.0.12 gatsby-plugin-offline: ^2.0.16 => 2.0.20 gatsby-plugin-react-helmet: ^3.0.2 => 3.0.5 gatsby-plugin-remove-trailing-slashes: ^2.0.6 => 2.0.6 gatsby-plugin-sharp: ^2.0.14 => 2.0.16 gatsby-source-filesystem: ^2.0.8 => 2.0.12 gatsby-transformer-sharp: ^2.1.8 => 2.1.9

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 22 (5 by maintainers)

Commits related to this issue

Most upvoted comments

The issue for me specifically was that the gatsby javascript was putting the trailing slash back in the URL after the page had loaded so that if a user were to refresh there page they would get a 301 which is not ideal.

Yes that’s exactly what I am talking about

not stale

Just in case anyone else comes across this issue, I’m solving the problem with a combination of Nginx configuration and the Gatsby remove trailing slashes plugin.

On the Nginx side I’m redirecting all trailing slash versions to the non trailing slash version This goes in my server block configuration

rewrite ^/(.*)/$ /$1 permanent;

You need the Gatsby plugin also because even though the server is redirecting all traffic to the non trailing slash version, the Gatsby javascript seems to be adding the trailing slash to the URL bar. If you use the plugin it will stop doing that.

To clarify Behaviour without plugin https://www.example.com/test will give a 200 response but the javascript will change the url bar to be https://www.example.com/test/

It should be also noted I’m not using gatsby serve anywhere anymore. We are using docker with a Nginx container instead.

bump, please reopen.

i’m seeing this with and w/o gatsby-plugin-remove-trailing-slash enabled.

also, linking #19543 to this

Yeah let me give it a shot.

Expected When visiting http://www.domain.com/prices There should be no redirect to http://www.domain.com/prices/

Google has recommemded that a site should pick a convention of whether or not to use trailing slashes and stick to it https://webmasters.googleblog.com/2010/04/to-slash-or-not-to-slash.html

Our team has decided that the non trailing slash version of our site is our convention and this is replacing and existing site so it’s important that we follow the same existing url conventions.

Actual http://www.domain.com/prices does a 301 redirect to http://www.domain.com/prices/

It is expected that ‘gasby develop’ and ‘gatsby serve’ work the same way