.htaccess - 在两个 React 应用程序之间重定向

问题描述

我在同一个子域中有两个 React 应用程序 - 在不同的目录中。

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

为了使反应路由器正常工作,我有现有的 .htaccess 规则将所有流量重定向到应用程序 (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]

我想允许在目录 /login 中加载 react 应用程序并且将所有 /login/* 请求重定向到 /login/index.html

如何使用 .htaccess 应用这些规则?

亲切的问候/K

解决方法

您现有的 .htaccess 没问题。只需在 .htaccess 目录下创建另一个 /login/,如下所示:

RewriteEngine On

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

这会将每个非文件和非目录 /login/* 请求路由到 /login/index.html

,

根据您展示的样品,您可以尝试以下操作吗?请确保在测试 URL 之前清除浏览器缓存。

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


OR uri 已开始登录,但 uri 中有其他内容。

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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...