This is my site I’m inquiring about: dainty-blancmange-21f6f7. It uses Next.js.
Here’s what I’m trying to do which works on local but not on Netlify. I have set the basepath to “/comeback” in my next.config.js but I also want any requests to / to redirect to /comeback. Here’s the full code:
Hi @Dan_Pearce, thanks for the post.
Kindly remove the netlify.toml and _redirects file and then change your next.config.js file to look like the code below.
Hi @Dan_Pearce, thanks for sharing the information.
However kindly explain what you actually want to achieve.
Initially you stated you wanted to set the base path and also redirect requests to / to redirect to /comeback
The second code snippet you shared containing Netlify forms does not explain what you actually want to achieve with regards to what you wanted to do initially.
I’m having a similar issue (Nextjs with basePath) where essentially basePath works on local dev and build but not on netlify.
It might be the same issue maybe?
I shared that page code because that’s the only thing that really differs from the default next.js code in create-next-app aside from the code you gave me in next.config.js. I thought sharing this code would be helpful since I cannot share the entire repository. I apologize if it led to confusion.
What I want to achieve has not changed. I would like to set the basepath to /comeback and have any requests to / redirect to /comeback and not return a 404.
Hi @Dan_Pearce, thanks for the feedback. It would be difficult for me to help without looking at some code.
However I suggest you take a look at the stackoverflow thread below as it is related to your situation in order to see if it helps.
Also take a look at the Netlify documentation page below if you have not done so already. It contains information that will guide you especially regarding root-level rewrites taking precedence over Next.js Runtime’s generated rewrites which breaks routing on your site.
This issue is resolved for us now after creating a brand new Next.js site and adding this to our netlify.toml:
[[redirects]]
from = "/"
to = "https://URL.com/"
status = 302
force = true
And also setting LEGACY_FALLBACK_FALSE=true in the build environment variables (not sure if that does anything to resolve it but I wanted to include it in case it does).