如何配置HTACCESS以删除index.php并重定向如果错误404



i当前有一个.htccess,当收到错误404时,它将重定向到404.html。现在我的问题是如何在URL中删除index.php。示例http://example.com/test/index.php。我希望它是http://example.com/test。

RewriteEngine on
RewriteCond % {REQUEST_FILENAME} !-f
RewriteCond % {REQUEST_FILENAME} !-d
RewriteRule ^ 404.html
ErrorDocument 404 /404.html

我正在使用xampp apache。

这应该像您在测试中所期望的那样重定向重写 ^(。*(/index.php $ $ 1 [l,QSA]

这是您可以看到测试的地方https://htaccess.madewithlove.be?share=78711E7E-4D95-5116-8C28-83D0362D3632

允许用户在访问"/test/"时允许用户执行"/test/index.php",可能是使用DirectoryIndex的最简单方法。只需将此行附加到您的.htaccess文件:

DirectoryIndex index.php

这将允许执行http://example.com/test/index.php。>

最新更新