Report this

What is the reason for this report?

Nextjs Export Redirect path without extension to path with .html

Posted on October 6, 2020

First of all thank you for the release of this product!

I have an app nextjs that I export in static and so I have a folder containing all my pages with the .html extension.

When the site is loaded and I click on a link in the page (next/link) the redirection is done. However, when I refresh the page, I get a 404 because he can’t find the page and expects to get .html at the end of the url.

Is it possible to redirect the url example.com/a to example.com/a.html automatically?

Kind regards



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

👋 @saikouah

App Platform doesn’t handle this type of routing. It will only do top-level routing. It sounds like you’ll want to use an internal router like next/router to handle routing inside of your app.

next/link works in the same way as next/router. You only have more freedom with the last one. The problem does not come from there but from the resolution of the routes directly.

  1. Go to example.com -> Click link example.com/a => works
  2. Go to example.com/a directly => does not work because there is no file that resolves this route.
  3. Go to example.com/a.html => works

The only solution for the moment is to deploy a webserver and run the next start command. But in doing so I lose the capability of the cdn? Or create another component that contains the deployment of the output of the next build (_next dir and other files) and have a webserver component that will run next start.

👋🏼 Like @crashoverride said this currently isn’t supported by App Platform however you can configure Next.js to generate the static HTML files in a way that allows you access the routes as /page instead of /page.html.

To enable this option, add the following to next.config.js:

module.exports = {
  trailingSlash: true,
}

This will generate the /page as /page/index.html instead of /page.html.

(documentation reference)

I’ve tested this and you can see an example in this repo: https://github.com/kamaln7/nextjs-static-index.html-example

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.