The default in next.js for static generation is to map this code:
/pages/p1.tsx
to this file:
/p1.html
The problem with that is that a link to /p1 will work when you use the next server, and will fail when you’re serving static files.
If you enable this, in next.config.js:
module.exports = {trailingSlash: true,}
Then you’ll get a different file:
/p1/index.html
And on most generic web servers (Apache out of the box, for example), you get this behavior:
/p1 - redirects to /p1/
/p1/ - serves /p1/index.html
/p1/index.html - serves /p1/index.html
So I think module.exports = {trailingSlash: true,}
gets you the behavior you’re expecting.
(@jdaz’s link to the other answer is definitely useful for this, but that question was very specifically about configuring .htaccess, so I’m repeating a similar answer here)