So I have a react single page application that I am hosting on cpanel. I have a pretty common issue from what I have been researching but none of the post in SO have helped me so far.
I am using React Router which I know is purely client-side routing. The problem is when the user refreshes the page on a url such as https://example.com/privacypolicy
I get the stand Not Found
error 404
.
My folder structure in cpanel is as follows:
home/mysite
public_html
all the folder from build folder (after npm run build locally)
index.html(important for the post)
.htaccess(important for the post)
The htaccess file is as follows:
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
I was hoping this was going to redirect all the requests to index.html and therefore react would know which component to render once that has been redirected.
It isn't and I'm a bit lost on what I'm doing wrong.
Any help is appreciated :)