score:0

create a file .htaccess file in react js root folder where index.html

and add the below code

    rewritebase /
    rewriterule ^index\.html$ - [l]
    rewritecond %{request_filename} !-f
    rewritecond %{request_filename} !-d
    rewriterule . /index.html [l]

save the .htaccess file and enjoy your working

score:0

this one works nice for me :

  # react router
  rewriteengine on
  rewritebase /
  rewriterule ^index\.html$ - [l]
  rewritecond %{request_filename} !-f
  rewritecond %{request_filename} !-d
  rewritecond %{request_filename} !-l
  rewriterule . /index.html [l]

score:1

can you share some error log screenshot or copy-paste ? 500 is a server-side error, obviously. maybe your routes on server are not matching the url pattern. or some express server route function threw an exception.

please, provide some logs from client and\or server.

upd: just mentioned the "static site" thing. didn't understand what exactly do you mean by that. for me it's no server at all.

still i'm pretty sure that your server has no routes configured.

server knows what is "/"("index.html"). but there are no routes configured for, say, "/potatoes".

in express server you would do something like:

app.get('*', function(req, res){
  res.sendfile(__dirname + '/index.html');
});
  • meaning, all get requests to your server(app) will lead the user to same "index.html".

score:3

your server's route should match the routes defined in the react-router, if they don't match then you will receive a 500 error.

score:8

when you’re visiting a route of your app directly, e.g. via https://myapp.com/route/123 apache tries to map that url to a file in the public folder. in this case it looks for /route/123.html which obviously doesn’t exist. to avoid that, we have to tell apache to redirect all requests to our index.html so our app can perform some routing magic for that url. to tell apache to redirect requests to index.html where our app lives, we have to modify the .htaccess file. if there is no such file in your app’s folder yet, just create it.

options -multiviews
rewriteengine on
rewritecond %{request_filename} !-f
rewriterule ^ index.html [qsa,l]

for more information check this out.


Related Query

More Query from same tag