gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:56:32 24 4
gpt4 key购买 nike

我正在使用 linux 操作系统和 apache。我在 public_html 中创建了一个 webapp 目录。在 public_html 我有一个登陆页面。我想保留这个着陆页。所有资源也可以获取。但我得到了 Page not found 错误。我发现我应该将所有请求发送到 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>

但我收到未找到消息错误:

https://parsebar.com/webapp/login

最佳答案

当我的 React 应用程序在子文件夹中运行时,我在 .htaccess 中使用了这个片段:

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

关于javascript - 如何将所有请求发送到 index.html - reactjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54177392/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com