Replies: 6 comments 11 replies
-
I am a bit confused here:
async rewrites() {
return {
beforeFiles: [
{
source: '/blog/:slug',
destination: 'https://B.com/blog/:slug',
},
],
};
}, I notice that the docs, do not use However, I don't follow what's the issue you are seeing, is the not browser showing |
Beta Was this translation helpful? Give feedback.
-
I have the same problem here. It looks like it works when it is a simple GET query but for POST I also get 307 Temporary Redirect. I am not 100% sure but could it be because the server side fetch crashes? This is my next.config.js
|
Beta Was this translation helpful? Give feedback.
-
I'm also having the same problem. Trying to use rewrites but see 301 redirect instead. |
Beta Was this translation helpful? Give feedback.
-
I had the same issue and I was able to resolve it. The server I was proxying to enforced a trailing slash so if /A was going to /B it would redirect to /B/ I fixed it by doing updating it from this:
to this:
|
Beta Was this translation helpful? Give feedback.
-
I'm having the same issue in a regular nextjs app, it redirects only in production, any insight @JohnAllen pls? |
Beta Was this translation helpful? Give feedback.
-
I think I've figured this out. Like @sbennettmarqeta said, part of the problem is the backend server enforcing a trailing slash. So nextjs really was proxying rather than redirecting, but the proxied response was itself a redirect, which told the client to request directly from the backend rather than the nextjs server. @ericvillemure's example looks the same as what I was getting: 307 is probably from the backend. In addition to that, nextjs itself will redirect requests that don't end in a trailing slash by default. That particular redirect is a 308 rather than a 307. So the client will make the request again without the trailing slash, which leads back to the first problem above. The combination makes this really confusing to debug. The good news is that the docs actually cover all this under https://nextjs.org/docs/api-reference/next.config.js/rewrites#rewriting-to-an-external-url, it's just so far down it's hard to notice. In that example code: module.exports = {
trailingSlash: true,
async rewrites() {
return [
{
source: '/blog/',
destination: 'https://example.com/blog/',
},
{
source: '/blog/:path*/',
destination: 'https://example.com/blog/:path*/',
},
]
},
} there are two fixes:
|
Beta Was this translation helpful? Give feedback.
-
Maybe I misunderstand how redirects are supposed to work (not middleware ones, next.config.js ones).
I'm trying to host a blog on WP and have an app run on Vercel. So in my next config I am rewriting any requests to /blog to my actual hosted blog url.
(my primary URL let's just call it myapp.com
My config is like this:
But when I do this, the final URL is just https://blog.url.com/blog/somepost and not myapp.com/blog/somepost.
Does this make sense?
I would appreciate any help understanding how rewrites are supposed to work.
Beta Was this translation helpful? Give feedback.
All reactions