Html 如何将子文件夹重定向到该子文件夹中的索引文件?

Html 如何将子文件夹重定向到该子文件夹中的索引文件?,html,.htaccess,redirect,Html,.htaccess,Redirect,当用户访问/subfolder/subfolder时,我使用此代码打开/subfolder/index.html [public_html/subfolder/.htaccess] DirectoryIndex redirect.php [public_html/subfolder/redirect.php] header("Location: http://website.com/subfolder/index.html"); die(); 但我认为这不是最优的。还有别的办法吗?(可能只使

当用户访问/subfolder/subfolder时,我使用此代码打开/subfolder/index.html

[public_html/subfolder/.htaccess]
DirectoryIndex redirect.php

[public_html/subfolder/redirect.php]
header("Location: http://website.com/subfolder/index.html");
die();

但我认为这不是最优的。还有别的办法吗?(可能只使用.htaccess文件)。非常感谢。

仅使用
DirectoryIndex.html
将加载index.html,但不会更改地址栏中的url

否则,您只需使用mod_alias中的
RedirectMatch

RedirectMatch ^/subfolder/?$ /subfolder/index.html

将以下代码放在子文件夹
.htaccess
文件中:

RewriteEngine on
RewriteRule  (.*)$  index.html
上述代码将任何/subfolder/request重定向到/subfolder/index.html