-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Q on the forced trailing '/' on URLs & redirects - What's happening here? #15317
Comments
Hello @pewStocky! You could try using Hopefully this works for you! Thanks for using Gatsby! 💜 💪 |
Hey @freiksenet - thanks for this we'll look into it. Regardless of whether that does work or not, is there any chance you're able to know why some tools / Google etc see that URL as non '/' even though it shows in the URL? Would be great to know re learning / knowledge of Gatsby etc. Thanks for your time / help! |
@pewStocky Apologies for missing this! What you're seeing is intended behaviour as far as I can tell. Let's go through this step by step:
Does that make sense? Now to solve your issue, I would just use the plugin that @freiksenet linked to and remove the nginx rewrite |
Hey Sid, Thank you so much for getting back to me! Super helpful. Few follow ups: 1: Why does Gatsby add a trailing slash by default? Can this be changed our side to not add it by default? 2: When Gatsby adds the '/' back in (because the URL is different to the canonical) what canonical URL is that looking at? One we've set ourselves? Also I believe our team tried that plugin but it didn't work... Thank you for the response though super helpful! |
Gatsby adds the trailing slash by default as a convention because it makes it easy to host sites on hosts that expect a trailing slash for pages in a folder (with an index.html file in the folder).
The canonical URL is the one that it generated by default (the one with the trailing slash). You can see these with a query like You can set it yourself when creating pages manually using the In case |
@pewStocky - When you say "Gatsby add a trailing slash by default", do you mean during development (i.e., localhost:8000) or on production (yourdomain.com) or both? I'm a bit confused, because GatsbyJS doesn't add trailing slash by default for me during development. However, I am using Netlify to deploy my site and there is a setting to enable "pretty URLs" that will automatically add trailing slash by default for my site on production. So during development, if I go to But on production, if I go to In my case, I prefer the pretty URLs and wanted to enable trailing slash by default during development so it matches production. At this point, I'm not able to figure out how to do that. |
Awesome thank you both, i'll discuss the above with our dev team and see what the situation is, and will try and provide the code to showcase the plugin isn't working etc Will update soon as we can thank you!!!!! |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! 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 for being a part of the Gatsby community! 💪💜 |
What needs doing right now to move this forward? The unwanted behaviour is that when opening a url without a trailing slash, the browser performs a 301 redirect to the trailing slash url Whether locally hosted or on netlify, regardless of whether 'gatsby-plugin-remove-trailing-slashes' is used, a 301 redirect is performed.
|
For me, without In development where I am removing the trailing slashes, I can see that the versions with the slashes are not created, but anyway I can access both versions from the browser and get a 200 status (first time it was a 304, after removing the cache I get a 200) *This created a minnor problem when importing a image with |
[Potential Fix]
Incredible! After your comment I checked my Netlify settings and indeed, everything is greyed out and looks as though Pretty URLs should be disabled but in fact, isn't.
To do this, you need to go into that option, manually untick Pretty URLs and lock it back up. That removed all traces of 301 for me.
Netlify > Build & Deploy > Post Processing > Asset Optimization > 'Disable
Asset Optimization' is ticked. Everything else is greyed out but ticked.
If I untick this option, untick Pretty URLs and retick 'Disable Asset
Optimization' I no longer have my 301 redirect issue!
So.. can we assume this is a weird UX issue with Netlify?
301 occurs with these settings...
![image](https://user-images.githubusercontent.com/48530756/64637527-4a1ec900-d404-11e9-8837-e7d1459475e1.png)
.. but not with these.
![image](https://user-images.githubusercontent.com/48530756/64637554-56a32180-d404-11e9-9912-8f5a5f84144e.png)
|
@dougwithseismic I think it is most likely a bug from their side, otherwise would be a very questionable UX decision. Thanks a ton for the help! This works for me! |
@dougwithseismic I somehow have stumped again against this, and I can confirm that making sure that Netlify pretty-urls is truly unclicked as you say effectively removes the redirect problem Thanks :) |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. Thanks for being a part of the Gatsby community! 💪💜 |
Hey again! It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Thanks again for being part of the Gatsby community! 💪💜 |
Was this closed in favour of #9207? Issue is still present and is still causing major SEO issues due to unwanted redirects |
This is a problem in AWS as well. Gatsby is a scam. |
Greetings all who arrive here from Google 👋🏻 For starters, please do not disable Pretty URLs on Netlify to solve this issue. That change does not solve this issue and instead serves your site's content on both the trailing slash and non-trailing slash versions of the paths, which tends to cause negative SEO results (duplicate content). This discussion was continued in the following Discussion thread here in the Gatsby repository and lead to an in-depth analysis on what's going on, why it's happening, and how to work with it: I strongly encourage newcomers / Google-comers to review that thread before following the above. |
Hey @jon-sully i found this via google as having the same issues for our Nuxt site. However, disabling pretty URLs, is in fact the right solution for us, because Nuxt already does this out of the box. but, as you say, for Gatsby that might not be right. i tested a trailing slash url, and even without the pretty url feature, it redirects to without. |
Greetings! And yeah, good to come back to this one from 2 years ago. I haven't kept up with the trailing slash stuff on Gatsby too much over the last two years but I believe Gatsby's most recent version does actually ship with trailing slash options baked in that render all prior tooling / packages useless? I haven't tested that, but I recall having discussions with the Gatsby team about the matter. YMMV! |
thanks @jon-sully . honestly been pulling my hair out (what little I have left) on this for days and finally found that little pretty url feature that was screwing everything up haha. was breaking all our 404s and stripping all query strings out so all the clients PPC ads were breaking. |
Hey all,
Before Gatsby integration we had our URLs as non trailing slash: /mortgage-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 '/':
However in the address bar, the URL still has a '/'
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
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!
The text was updated successfully, but these errors were encountered: