.htaccess 使用 React Router 重写 React

PCD*_*Man 0 .htaccess

我需要重写或添加到我现有的 .htaccess 文件,以便我的托管服务 (Hostinger) 可以对所有页面使用单个 index.html 文件,而不是尝试在服务器端获取新文件。我正在将 React 与 React-Router 一起使用,但它不了解如何正确使用路径。

现有文件:

这用于解决我的 SSL 问题

========================== 文件 ======================== ====

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.matthewendicott.space/$1 [L,R=301] 

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.matthewendicott.space/$1 [L,R=301]
Run Code Online (Sandbox Code Playgroud)

====================== 测试和类似问题==============

以下是我尝试过的一些事情:

https://hostpapasupport.com/set-301-permanent-redirect-using-htaccess/

https://mediatemple.net/community/products/grid/204643080/how-do-i-redirect-my-site-using-a-htaccess-file

这是一个类似的问题:

在反应中直接访问组件时如何修复“404”错误

PCD*_*Man 8

如果有人需要这方面的帮助,我可以与我在 Hostinger 的朋友一起工作,这是您的 .htaccess 文件需要包含的内容。

完全复制和粘贴:

<IfModule mod_rewrite.c>

  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteRule . /index.html [L]

</IfModule>
Run Code Online (Sandbox Code Playgroud)

  • 奇迹般有效 (2认同)