目标:.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>
要将
.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
。