Next.js Discord

Discord Forum

Problem: When I refresh the page on some different route let's say /about, it brings the index.js pa

Unanswered
Netherland Dwarf posted this in #help-forum
Open in Discord
Avatar
Netherland DwarfOP
Hey ! i working on a project with nextjs and nodejs using nextjs just for the frontend and nodejs for the backend. i hosted the node app on cpanel, build the nextjs app and hosted then content of the out folder in cpanel too( in the public_html folder). my i'm is hosted successfully and works well but i have an issue. the issue is that when i reload the browser or app, it always brings me to the entry point file (index.html).so i can navigate through all my routes but let's say i am in the route product and reload the page or browser it will bring me to the home page and it's not a correct behavior because it should still be in the product page. and also it brings me the content of the home page but the url of the product page on the browser stay's it don't switch to "/"(home pag). this is my .htaccess configuration.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# Serve existing files or directories directly
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# Rewrite all other requests to the root index.html
RewriteRule ^ /index.html [L]
</IfModule>

3 Replies

Avatar
@Netherland Dwarf can you give more context like project structure
Avatar
Netherland DwarfOP
okay so the next app just used for the frontend nothing more and i'm using the dynamique routing system of next (that is folder-like ). i build my project then got the out folder which have static files in it. so i zip the content of the out folder then uploaded it on cpanel. i can access the app with no problem , i can move from one route to another with no problem. but when i reload the page or the browser reloads its self, i'm always brought back to the main route which is the index.html file. and in the root of the public_html folder in cpanel the index.html file is present with all the other files of the app like about.html . when i remove the the condition in the .htaccess file that says all routes not found fall back on the index.html, when the page is reload i'm brought to a 404. so it's like with my configuration in the .htaccess it can only locate the index.html files when the browser reloads and not the other files
Avatar
can you send me link of your project, or project structure (use tree command)