使用.htaccess将所有子文件夹的目录重定向到Root(主)目录

问题描述 投票:0回答:1

假设我的域名是http://example.com/,我有一个页面,如http://example.com/abc/(使用重写规则删除页面文件的扩展名)。

但有时,用户类型http://example.com/abc/xxx/(xxx是各种各样的,他们键入的机会很多),如http://example.com/abc/1njnsdchttp://example.com/abc/diief123/等。通常,它会向服务器请求/abc/xxx//abc/injnsdc//abc/diief123/等。不幸的是,我们没有文件夹/abc/里面的文件所以服务器应该返回404错误,找不到。

我希望制作一个重写规则来使服务器获取请求,如http://example.com/abc/xxx/http://example.com/abc/1njnsdc/http://example.com/abc/diief123/将不会返回404,但会响应重定向到http://example.com/abc/。我的另一个静态请求是URL无法更改。因此,一旦用户键入http://example.com/abc/xxx/http://example.com/abc/1njnsdc/http://example.com/abc/diief123/等,所有这些都可以访问用户类型http://example.com/abc/???/。并且用户仍在阅读页面http://example.com/abc/

apache .htaccess redirect mod-rewrite
1个回答
0
投票

您可以尝试将404页面重定向到主页面!如果你不想让它显示出来。如果您使用的是php,这可能对您有用:

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url'));
exit();
?>
© www.soinside.com 2019 - 2024. All rights reserved.