dmerckx
September 3, 2020, 11:03am
8
I finally got this working.
Thanks to these comments:
opened 04:45PM - 02 Jul 19 UTC
closed 12:07AM - 14 Dec 19 UTC
type: question or discussion
stale?
Hey all,
Before Gatsby integration we had our URLs as non trailing slash: /mo… rtgage-calculator
Since remaking certain pages in Gatsby my team have said that Gatsby 'forces' a trailing slash: /mortgage-calculator/
We previously had a server side redirect setup (nginx) to remove the trailing slash.
If you go to the '/' URL version, you get redirected to the non '/':
![image](https://user-images.githubusercontent.com/51830873/60530557-e9329080-9cf0-11e9-8c59-53ccac7b79a0.png)
However in the address bar, the URL still has a '/'
![image](https://user-images.githubusercontent.com/51830873/60530576-f485bc00-9cf0-11e9-8c0f-923a6b55dc83.png)
The fact that this '/' doesn't seem to be getting picked up seems to be confirmed by checking the HTTP status code of the non '/' URLs: /mortgage-calculator
![image](https://user-images.githubusercontent.com/51830873/60530149-0f0b6580-9cf0-11e9-91bc-0a83595d35ea.png)
Can anyone advise what is happening here? I thought '/' were forced but currently this '/' seems more like a 'cosmetic' '/' and not an actual coded '/'
Apologies in advance for any newbie language and thank you for any help!
opened 11:40AM - 18 Oct 18 UTC
closed 09:49AM - 27 Nov 20 UTC
type: bug
help wanted
type: upstream
## Summary
URLs with no trailing slash on sites hosted by Netlify lead to an … immediate 301 redirect to the page with a trailing slash.
``foo.com/bar`` --> ``foo.com/bar/``
This has a performance cost and implications for SEO.
_Is there a Netlify configuration that resolves these URLs without redirecting?_
## Relevant information
While this question is specific to Netlify, I did a quick review of other Gatsby sites featured in the Showcase and saw the same behaviour in many, but not all cases, for example:
[Hopper /company](https://www.hopper.com/company) - 301 redirect (Netlify)
[Impossible Foods /mission](https://impossiblefoods.com/mission) - 301 redirect (unknown)
[Cajun Bow Fishing /bows](https://cajunbowfishing.com/category/bows) - 301 redirect (Netllify)
[Braun /shavers-for-men](https://ca.braun.com/en-ca/male-grooming/shavers-for-men) - 200 no redirect (unknown)
### Environment (if relevant)
Same behaviour in Gatsby v1 and v2.
I'm using [gatsby-plugin-remove-trailing-slashes](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-remove-trailing-slashes) and [gatsby-plugin-netlify](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-netlify).
Within the project all Links point to the non-trailing slash version.
So something very weird is going on with the netlify UI.
The only way to skip the redirect is to ‘Disable asset optimization’ but also explicitly check all the boxes except for ‘Pretty URLs’:
Simply checking ‘Disable asset optimization’ without checking the other boxes does not work, the redirect still occurs.
The problem is unrelated to whether I build from Gatsby Cloud or Netlify directly.
I got all my sites working correctly as soon as I configured this.
3 Likes