T
T
todaystudio2022-04-17 22:16:42
Apache HTTP Server
todaystudio, 2022-04-17 22:16:42

How to host a React app with routing?

I have a React application with routing (react-router-dom) and FireBase. And there is so far a test hosting (Apache). I made a build yarn run buildand uploaded it to hosting. The main page opens, and when you enter site.ru/admin, 404 comes out.
I threw all possible .htaccess options, but to no avail.
Tell me how to implement it correctly so that routing works.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mletov, 2022-04-18
@mletov

Have you tried this .htaccess option? Helped me.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdirectory
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>

If it doesn't help, then check if any .htaccess rules are processed at all.
If not, then write to the hosting admins. Sometimes the server is configured in such a way that the settings from .htaccess do not work in whole or in part.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question