Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a page route with html extension on nextjs

I need to convert a non-nextjs page to nextjs. In order to not lose my SEO ranking, I have to create the route with html extension. To make the picture look better, I am adding the folder structure down below.

enter image description here

Unfortunately, this route ending up as 404 on the browser.

enter image description here

What is the problem? Am I allowed to use Next.js routes like that with html extension?

like image 796
cooskun Avatar asked Dec 19 '25 08:12

cooskun


1 Answers

You can do this via the pageExtensions option in nextJS -

I deployed a vercel app to show how this is working

https://html-ext.vercel.app/search-results.html

Steps

  1. Add the pageExtensions to next.config.js files i.e
pageExtensions: ['html', 'jsx', 'js', 'tsx', 'ts'],
  1. Rename the file under pages directory to .html.js - search-results.html.js in this case.
like image 108
Ramakay Avatar answered Dec 20 '25 22:12

Ramakay