I'm using the react router dom for my frontend routing, but whenever I refresh the page or access any URL which isn't the root or '/' the server responds with a 404, before I ran npm build the router worked just fine even if I refreshed the page.
Asked
Active
Viewed 243 times
2 Answers
0
You should add .htaccess
(server configuration) file to your remote Apache server's directory with the following code (forces https):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /index.html [NC,L]
</IfModule>
Without forcing https:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]

Пламен Дарджиков
- 26
- 4
-
I'm using nginx – Raúl M Jun 24 '21 at 19:24
0

Abhijit Sil
- 191
- 4
-
Thanks the last article was really helpful, I had tried but wasn't restarting nginx, I've restarted it and everything works just fine! – Raúl M Jun 25 '21 at 02:42