How do I create a 404 redirect?

0 votes
My website is basically a React app, which means all routing is done on the front-end. If I happen to refresh a dynamic URL created by React I will be given a 404 error.

How can I redirect to my home page each time there is a 404 error?
asked Feb 15 in Shared Hosting by Cryptic (200 points)
edited Feb 15 by Cryptic

1 Answer

0 votes
 
Best answer

The .htaccess file is hidden. So the only way to create a redirect is to create your own .htaccess file on your PC and overwrite it by uploading it on the server. This answer was useful: https://answers.afrihost.com/33/how-do-i-create-a-htaccess-file

This is the process I basically went through in case anyone else has a problem:

1) Click on the htaccesseditor link suggested on https://answers.afrihost.com/33/how-do-i-create-a-htaccess-file.
2) Once your on the website click on 'Error Page (E)'. Type in the URL of where your 404 errors should redirect to.
3) Click on 'Default Page (D)'. Type in the filename + extension (eg. index.html).
4) Click on 'Setup WWW (W)'. Type in the URL of your website.
5) Create a file called '.htaccess' on your PC. Copy the content into your '.htaccess' file.
6) Upload the '.htaccess' to your 'public_html' folder. Click Yes if requested to overwrite.

answered Feb 16 by Cryptic (200 points)
...