如何通过.htaccess正确地将index.php重定向到另一个页面?

Sam*_*Sam 5 apache indexing .htaccess mod-rewrite redirect

目前我的htaccess文件包含此规则,以将website.org/index.php重定向到 website.org/en/home

RewriteRule index.php /en/home [R=301]
Run Code Online (Sandbox Code Playgroud)

但是,目前还有index.php更深层文件夹中的其他页面重定向!例如,website.org/folder/index.php重定向到website.org/en/home

如何将该规则专门应用于根目录,而不是更深层的文件夹?非常感谢.

Zim*_*bao 9

RewriteRule ^index.php /en/home [R=301]
Run Code Online (Sandbox Code Playgroud)

  • 否。^ 表示字符串的开头。您正在尝试匹配相对于 .htaccess 所在文件夹的 url 路径。在本例中是index.php。如果是你的前任。url website.org/folder/index.php,index.php 匹配folder/index.php 并进行重定向。现在,使用 ^index.php 它不匹配文件夹/index.php,因为此 url 以文件夹开头。 (2认同)