2

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 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.