score:5

Accepted answer

it turns out that i was using a windows iis server. i'm new to the world of web servers and didn't know that i was working with an iis server.

it turns out that i needed a web.config file to make my url redirects work, and not a .htaccess file, like i was trying to use initially.

this is the content (found from this stackoverflow answer) of my web.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webserver>
    <httperrors errormode="custom" existingresponse="replace">
        <remove statuscode="404" substatuscode="-1" />
        <error statuscode="404" path="/" responsemode="executeurl" />
    </httperrors>
  </system.webserver>
</configuration>

score:0

try specifying your homepage in your package.json file

{
"homepage": "https://yoursite.com",
}

then run

npm build

or

yarn build

score:14

if you are using and apache server the problem might be your .htaccess file, when you are using react router the routes that are created or declared in react do not exist in the server, therefore we have to configure the requests so that each one goes to index.html and show a 404 in react when the page is not found.

according to the create-react-app documentation:

if you are using apache http server, you need to create a .htaccess file in the public folder that looks like this:

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

link to create-react-app documentation:

https://create-react-app.dev/docs/deployment

you can read more about the creation of a 404 page in react in the react router: documentation:

https://reacttraining.com/react-router/web/example/no-match


Related Query

More Query from same tag