I want to host the Nextjs website on Hostinger so I export Nextjs as static in (out) directory using output: 'export'
in next config
I uploaded the static files on hostinger and it worked. but once you refresh any page except the home page, Hostinger can't serve the page and shows a 404 page
So what is the issue here and how can I debug it
I found the issue which is url doesn't explicitly contain .html
at the end
because when the route, for example, is /test
, apache on Hostinger is looking for a directory call test
and has index.html
file but instead nextjs export html files with their names test.html
so apache can't find this directory and return 404
.
the solution is to create .htaccess
file inside public_html
directory and configure the apache to serve HTML files by their names
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule !.*\.html$ %{REQUEST_FILENAME}.html [L]