Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Next.js app routing not working after deployment to cPanel

I just deployed my next app on cPanel using buddy works and Github. The overall process was fluent and working properly and i was able to upload my .next folder to public.html folder of cPanel. But after uploading the files and visiting the domain i found that the only page that was correctly rendered was the first page with the route ('/'). On clicking on other routes i was met with the following error page

Error displayed on all other routes

Only after adding .html extension to the end of the route i was able to get the desired page. Attaching the screenshot for that here

enter image description here

I have gone through all the next js documentation available and i still am not able to sort this issue out properly. If anyone can point to what i am doing wrong here would be great help. Thanks!

like image 921
Wakas Abbasid Avatar asked Sep 13 '25 12:09

Wakas Abbasid


1 Answers

You have to add trailingSlash key in next.config.js as follows:

module.exports = {
  trailingSlash: true,
  ...
}

and then build your project in the same way you are building now.

like image 117
Shubham Waje Avatar answered Sep 16 '25 01:09

Shubham Waje