htaccess的重定向循环!所有子目录的根子目录、重定向、htaccess

2023-09-02 01:14:02 作者:看谁笑到最后

我想通过的.htaccess重定向所有子目录到我的网站的根! 下面的code工作正常,如果我试图访问一个子目录...但不会让我显示根索引页,因为启动重定向的循环!

I'm trying to redirect all subdirectories to the root of my website via .htaccess! The code below works fine if I try to access a subdirectory ... but doesn't let me display the index page in the root because starts a loop of redirects!

RedirectMatch temp ^/.*$ http://localhost/

我该如何解决这个问题?

How can I solve this?

推荐答案

如果您希望所有subdirectores重定向到主页,你会做这样的事情:

If you want all subdirectores to redirect to the home page, you would do something like this:

RedirectMatch temp ^/.+/.*$ http://localhost/

这将匹配任何URI在这两条斜线,跟他们之间至少有一个字符。

This will match any URI with two slashes in it, with at least one character between them.