Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.3K
Vistas
Configuring .htaccess for React applications (+Router) inside a subdirectory

I have a React application which is located in the mysite.com/admin directory. So index.html is located in mysite.com/admin/index.html. The application contains routes like /admin/users or /admin/tools/removeUser.

How do I configure .htaccess to load mysite.com/admin/index.html when I open mysite.com/admin/ for exapmle? The url itself should remain the same in order to render necessary route.

Should say that there is also a React app in the root directory. Here is what I tried:

RewriteEngine on
RewriteBase /

#for app in subdirectory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^admin admin/index.html [L]

#for root app
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]

But when I open mysite.com/admin/tools/removeUser for example, in the console I get this error:

enter image description here

What am I doing wrong?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You're right.

Potential problem.

When run on local server Node JS routing (components are BrowserRouter, Switch, Route ) is work fine. Opening direct link and reload page correct work. But when deploy on web server Apache are situation, start component app work (because page don’t reload), but when reload page then appear 404 page. The same page 404 appear when opening direct link contens a part of route app. Server Appache requires correct settings in file .httpaccess For example I have two CMS on server apache and one of them is SPA. Мy CMS should have rules and another system like SPA should have rules in .httpaccess

Possible solutions:


    RewriteEngine on
    #for app in subdirectory
    RewriteBase /admin/
    RewriteRule ^index\.html$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^.*admin/.* /admin/index.html [L]
    #for root app
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule . /index.html [L]

It is important that the rules for the application subdirectory do not overwrite the rules for the main application

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda