代码之家  ›  专栏  ›  技术社区  ›  S.M_Emamian

如何将所有请求发送到index.html-reactjs

  •  0
  • S.M_Emamian  · 技术社区  · 6 年前

    我使用的是linux操作系统和apache。 我创造了一个 webapp 内部目录 public_html . 里面 公共HTML 我有一个登录页。我想保留这个登录页。 所有的资源都可以获取。 但我发现页面未找到错误。 我发现我应该把所有的请求发送给 index.html 文件。

    .htaccess文件:

    <ifModule mod_rewrite.c>
    
    
      #######################################################################
      # GENERAL                                                             #
      #######################################################################
    
      # Make apache follow sym links to files
      Options +FollowSymLinks
      # If somebody opens a folder, hide all files from the resulting folder list
      IndexIgnore */*
    
    
      #######################################################################
      # REWRITING                                                           #
      #######################################################################
    
      # Enable rewriting
      RewriteEngine On
    
      # If its not HTTPS
      RewriteCond %{HTTPS} off
    
      # Comment out the RewriteCond above, and uncomment the RewriteCond below if you're using a load balancer (e.g. CloudFlare) for SSL
      # RewriteCond %{HTTP:X-Forwarded-Proto} !https
    
      # Redirect to the same URL with https://, ignoring all further rules if this one is in effect
      RewriteRule ^(.*) https://%{HTTP_HOST}/$1 [R,L]
    
      # If we get to here, it means we are on https://
    
      # If the file with the specified name in the browser doesn't exist
      RewriteCond %{REQUEST_FILENAME} !-f
    
      # and the directory with the specified name in the browser doesn't exist
      RewriteCond %{REQUEST_FILENAME} !-d
    
      # and we are not opening the root already (otherwise we get a redirect loop)
      RewriteCond %{REQUEST_FILENAME} !\/$
    
      # Rewrite all requests to the root
      RewriteRule ^(.*) /
    
    </ifModule>
    
    <IfModule mod_headers.c>
      # Do not cache sw.js, required for offline-first updates.
      <FilesMatch "sw\.js$">
        Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
        Header set Pragma "no-cache"
      </FilesMatch>
    </IfModule>
    

    但我得到了 not found 消息错误:

    https://parsebar.com/webapp/login

    1 回复  |  直到 6 年前
        1
  •  0
  •   phifa    6 年前

    我在我的 .htaccess 当我的React应用程序在子文件夹中运行时:

        Options -MultiViews
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.html [QSA,L]