-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
trailingSlash: true redirects /_next/image? to /_next/image/? for each image request #21337
Comments
+1 Can reproduce the same bug, multiple 308 redirects and then leading to the error |
The error
|
It's not that, i checked my request, it had url parameter, but after first 308 redirect, the url param was getting stripped from the request and then eventually getting |
For those who have run into the same problem here is the solution. I dug into the code for the image component and found how to fix the issue. You can predefine the path for the images in the next.config images configuration path by adding a trailing slash and the redirects stop: However, I didn't know I could do this, because as per the documentation it seems that one can only use the path property when configuring an external logic. Maybe the documentation should be extended with a sentence or two to explain how it works - not only in the loader section. Also since this is an internal behavior of NextJS, perhaps, it should be covered inside the code and the /_next/image route should be an exception from the rule for trailing slash. |
I tried adding The usual request with
Path of the image is The request with
Response with Please help me know if I am doing anything wrong here or am i missing any param or something. |
…n in default loader vercel#21337
In next.config .js stopped 308s for me as well. |
i'm using |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
What version of Next.js are you using?
10.0.2
What version of Node.js are you using?
12.4.1
What browser are you using?
Chrome
What operating system are you using?
Windows
How are you deploying your application?
Other platform
Describe the Bug
When trailingSlash is set to 'true' the /_next/image directory used for serving optimized images is also affected.
Instead of requesting the resource on:
/_next/image?url=/uploads/...
the user is redirected with 308 to
/_next/image/?url=/uploads/...
This creates a huge amount of unnecessary redirects for a page full of images. I couldn't find any additional config options for the trailingSlash option whatsoever.
Expected Behavior
The optimized images path to not be redirected to a path with a trailing slash.
To Reproduce
The text was updated successfully, but these errors were encountered: