从S3和CloudFront上的URL react应用程序中删除index.html



我在一个s3 bucket上托管多个react应用程序,该bucket连接到CloudFront发行版。react应用程序被放置在文件夹中,因此例如计算应用程序位于S3存储桶中。我修复了发生的问题,因为react没有以相对于index.html的方式使用路径(我在包.json中添加了"homepage":"./"(。但我很难从最终用户的URL中删除index.html。基本上,我希望index.html在访问https://{domain}/caculate/时出现,而不是https://{domain}/caculate/index.html。有人知道如何解决这个问题吗?

感谢

您可以创建一个名为"的文件;。htaccess";在根目录中,并向其中添加以下内容:

RewriteEngine on
# Remove .html (or htm) from visible URL (permanent redirect)
RewriteCond %{REQUEST_URI} ^/(.+).html?$ [nocase]
RewriteRule ^ /%1 [L,R=301]
# Quietly point back to the HTML file (temporary/undefined redirect):
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [END]

最新更新