Skip to content
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

[Bug]: Trailing slash not working #1329

Closed
2 tasks
scajal opened this issue Apr 27, 2022 · 12 comments
Closed
2 tasks

[Bug]: Trailing slash not working #1329

scajal opened this issue Apr 27, 2022 · 12 comments
Assignees
Labels
type: bug code to address defects in shipped code

Comments

@scajal
Copy link

scajal commented Apr 27, 2022

Summary

The option trailingSlash: true is not working when deploying a site.
The site also has Pretty URLs option activated in the deploy settings.
Some links work with the slash (but have both versions, which is bad for SEO).

The only pages that are working with trailing slash are server side pages.

Steps to reproduce

  1. Access https://cerulean-travesseiro-e6b413.netlify.app/ and visit the different links

A link to a reproduction repository

https://github.com/scajal/netlify-test

Plugin version

4.7.0

More information about your build

  • I am building using the CLI
  • I am building using file-based configuration (netlify.toml)

What OS are you using?

No response

Your netlify.toml file

`netlify.toml`
# Paste content of your `netlify.toml` file here

Your public/_redirects file

`_redirects`
# Paste content of your `_redirects` file here

Your next.config.js file

`next.config.js`
/** @type {import('next').NextConfig} */
const nextConfig = {
	/** @see https://nextjs.org/docs/api-reference/next.config.js/react-strict-mode */
	reactStrictMode: true,

	/** @see https://nextjs.org/docs/api-reference/next.config.js/trailing-slash */
	trailingSlash: true,
};

module.exports = nextConfig;

Builds logs (or link to your logs)

Build logs

Function logs

Function logs

.next JSON files

generated .next JSON files
# Paste file contents here. Please check there isn't any private info in them
# You can either build locally, or download the deploy from Netlify by clicking the arrow next to the deploy time.
@scajal scajal added the type: bug code to address defects in shipped code label Apr 27, 2022
@scajal

This comment was marked as off-topic.

@gnevin
Copy link

gnevin commented May 4, 2022

I'm experiencing the same issue with ISR pages. The trailingSlash option is being disregarded and both trailing and non-trailing are being served, causing duplicate content SEO issues.

@scajal
Copy link
Author

scajal commented May 4, 2022

I've updated the issue with a public repository and a public deployed site with a static, a SSG and a SSR page. The only page where the trailing slash is being added is in the SSR page.

@scajal
Copy link
Author

scajal commented Jun 6, 2022

Anyone can check this?

@shubhendusaurabh
Copy link

I'm facing the same problem in netlify, works correctly in vercel.

directly going to /path/ results in 301 redirection to /path. however client side navigation works correctly.

i was able to stop 301 redirect by enabling pretty urls in asset optimization but the same page is duplicated in 2 different urls i.e. /path and /path/ which is bad for SEO.

@ericapisani ericapisani self-assigned this Jun 14, 2022
@ericapisani
Copy link
Contributor

Hi all!

First off, thanks @scajal for the initial issue submission and the repro and thanks @gnevin and @shubhendusaurabh for the additional information.

Unfortunately this is not a bug with the plugin but is behaviour resulting from our logic on the Netlify CDN aimed at keeping site performance high by maximizing the cache hit rate. I've raised this issue with the related team and confirmed that this behaviour is not configurable, but have asked about further investigation into ways to mitigate or address the SEO issues that are being caused as a result of the page duplication that's been mentioned here.

I had investigated trying to create an edge function that would've supported this behaviour as a workaround, but unfortunately that kind of redirect causes an infinite loop because the resulting paths are essentially the same.

Related Netlify docs for those interested in reading a bit more can be found here

Because this is an issue resulting from behaviour with the CDN and not the plugin, this bug will be closed as 'won't fix/do', but please don't hesitate to ask any follow up questions here.

@ericapisani ericapisani closed this as not planned Won't fix, can't repro, duplicate, stale Jun 16, 2022
@ascorbic
Copy link
Member

I've made a quick demo of using edge functions to strip the trailing slashes. I will add an equivalent to add the slashes. It works around the different ways the CDN defines the canonical URL. We will add this to the plugin so it works by default according to the next config, but for now you can add it manually.

https://github.com/ascorbic/slash-edge

@scajal
Copy link
Author

scajal commented Jun 17, 2022

Hi @ascorbic, your solution is not working for me, it throws ERR_TOO_MANY_REDIRECTS in the browser.

@ascorbic
Copy link
Member

@scajal can you try with an updated version?

@grahamd711
Copy link

thank you @ascorbic ! your solution works for our Next.js app on Netlify

@kavita2599
Copy link

@scajal can you try with an updated version?

Which updated version should I use? I am also facing the same redirects too many times issue

@samlogan
Copy link

Hey, @ascorbic, I'm unsure if there's been an update on Netlify's side, but I am getting the redirect issue with top-level pages; I also see this on your demo.

CleanShot 2024-03-12 at 15 46 08@2x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

8 participants