【问题标题】:.htaccess - redirect between two react apps.htaccess - 在两个反应应用程序之间重定向
【发布时间】:2021-04-09 13:17:18
【问题描述】:

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

  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

【问题讨论】:

    标签: reactjs .htaccess mod-rewrite url-rewriting friendly-url


    【解决方案1】:

    您现有的 .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

    【讨论】:

      【解决方案2】:

      对于您显示的示例,您能否尝试以下操作。请确保在测试 URL 之前清除浏览器缓存。

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


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

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

      【讨论】:

        猜你喜欢
        • 2022-11-17
        • 1970-01-01
        • 2022-01-24
        • 1970-01-01
        • 2022-01-18
        • 2019-05-19
        • 1970-01-01
        • 2015-07-18
        • 2018-04-19
        相关资源
        最近更新 更多