.htaccess - redirect between two react apps

Viewed 311

I have two react apps in the same subdomain - in different directories.

  1. app.domain.com
  2. app.domain.com/login

For react router to work I have existing .htaccess rules to redirect all traffic to the app (index.html)

RewriteEngine On

#Redirect to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteBase /

#Not sure what this does
RewriteCond %{QUERY_STRING} ^open&guid= 
RewriteRule ^ ? [R=301,L,NE]

#Not sure what this does
RewriteRule ^index\.html$ - [L]

#Redirect all to index.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

I want to allow to load the react app in directory /login and redirect all /login/* requests to /login/index.html.

How can I apply these rules using .htaccess?

Kind regards /K

2 Answers

Your existing .htaccess is fine. Just create another .htaccess under /login/ directory as this:

RewriteEngine On

#Redirect all to index.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.html [L]

This will route every non-file and non-directory /login/* request to /login/index.html

With your shown samples, could you please try following. Please make sure you clear your browser cache before testing URLs.

RewriteRule ^login/?$  login/index.html [NC,L]


OR uri has starting login with having other things in uri.

RewriteRule ^login(?!=index\.html)  login/index.html [NC,L]
Related