.htaccess - 在两个反应应用程序之间重定向
.htaccess - redirect between two react apps
我在同一个子域中有两个 React 应用程序 - 在不同的目录中。
- app.domain.com
- app.domain.com/login
为了让 React 路由器正常工作,我有现有的 .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 没问题。只需在 /login/
目录下创建另一个 .htaccess
,如下所示:
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]
或者 uri 已开始登录,但 uri 中有其他内容。
RewriteRule ^login(?!=index\.html) login/index.html [NC,L]
我在同一个子域中有两个 React 应用程序 - 在不同的目录中。
- app.domain.com
- app.domain.com/login
为了让 React 路由器正常工作,我有现有的 .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 没问题。只需在 /login/
目录下创建另一个 .htaccess
,如下所示:
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]
或者 uri 已开始登录,但 uri 中有其他内容。
RewriteRule ^login(?!=index\.html) login/index.html [NC,L]