如何使用子文件夹设置.htaccess并指向dist文件夹

问题描述 投票:0回答:1

目标:.htaccess 配置指向 dist 文件夹中的 index.html

根目录下的文件夹:api、main 和 admin。

主文件夹内有一个名为dist的文件夹,里面是VITE编译的文件,如index.html,assets,img等

这是我当前的 .htaccess 配置

<IfModule mod_negotiation.c>
 Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index\.html$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.html [L]
</IfModule>
vue.js .htaccess
1个回答
0
投票

要将

.htaccess
文件配置为指向
index.html
目录的
dist
文件夹内的
main
文件,您需要相应地修改
RewriteRule
。这是更新后的配置:

<IfModule mod_negotiation.c>
 Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index\.html$ main/dist/index.html [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /main/dist/index.html [L]
</IfModule>

此配置假设您的

.htaccess
文件位于根目录中,并且会将
index.html
的请求重定向到
main/dist/index.html
(如果存在)。如果请求的文件不存在,仍然会重定向到
main/dist/index.html

© www.soinside.com 2019 - 2024. All rights reserved.