Reputation: 21
I am new in Reactjs, and I am working on Reactjs v15.4.2. When i build the code for production using "npm run build" cmd and uploaded to server. Everything thing working fine but once I reload or refresh the page then getting 404 file not found error.
Can anyone please help me to solve this problem. Thanks in advance.
Upvotes: 1
Views: 1821
Reputation: 21
I have added this code to root directory. This is working fine for me
RewriteEngine On RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR] RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d RewriteRule ^ - [L] RewriteRule ^ /index.html [L]
Upvotes: 1
Reputation: 151
This can be resolved by adding a .htaccess file to root of the app with the following code :
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteCond %{REQUEST_URI} !.*\.(css¦js|html|png)
RewriteRule (.*) index.html [L]
</ifModule>
Hope that helps.
Upvotes: 1