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

paths contain dots with trailingSlash:true are forced to be accessed without trailing slash #16617

Closed
TasukuUno opened this issue Aug 27, 2020 · 6 comments

Comments

@TasukuUno
Copy link
Contributor

Bug report

Describe the bug

In my project, I have URLs with id contains dots as dynamic routes and want to keep them accessible with a trailing slash.

like:
https://github.com/vercel/next.js/
https://example.com/foo/this.is.not.a.file.but.id/

However, the following first RegExp treats them as file path and we can't access with trailing slash.

Redirects
┌ source: /:file((?:[^/]+/)*[^/]+\.\w+)/
├ destination: /:file
└ permanent: true
┌ source: /:notfile((?:[^/]+/)*[^/\.]+)
├ destination: /:notfile/
└ permanent: true

To Reproduce

  1. set trailingSlash: true in next.config
  2. add a dynamic route like /pages/foo/[id].tsx
  3. access /foo/a.b.c/ in browser
  4. server will respond with a redirect to /foo/a.b.c

Expected behavior

Server should respond the html as /foo/a.b.c/.

Screenshots

image

System information

  • OS: macOS
  • Browser: chrome
  • Version of Next.js: 9.5.2
  • Version of Node.js: v14.3.0
@timneutkens
Copy link
Member

timneutkens commented Aug 30, 2020

Paths with an extension are expectedly redirected in this way to ensure you don't get double requests for static files that do not have a trailing slash.

@TasukuUno
Copy link
Contributor Author

I understand the intention for static files. express.static also responds redirect responses in this case. But is it difficult to treat pre-defined dynamic routes as exception?
This trailingSlash: true option is not available for our use case.

@shorn
Copy link

shorn commented Sep 9, 2020

Just got bit by this for a simple statically generated site with a page like src/pages/blog/2020/version-1.23.tsx.

I am using v9.5.3.
My workaround is to not name pages that way - just going to rename my version release pages to version-1-23.tsx etc.

Would be polite to give folks a heads-up on the trailingSlash page though - there's no need to for people to be surprised by this.

@timneutkens
Copy link
Member

Would be polite to give folks a heads-up on the trailingSlash page though - there's no need to for people to be surprised by this.

Feel free to send a PR to the docs!

@Zauberfisch
Copy link

I think not only related to #18164, but a duplicate, which should be closed

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants