Apache重定向文件夹下的所有内容,但文件夹本身除外

Apache重定向文件夹下的所有内容,但文件夹本身除外,apache,redirect,rewrite,Apache,Redirect,Rewrite,在过去的某个时候,我们的网站的结构类似于www.example.com/departments/it或www.example.com/departments/asdf。然后,路径变为类似www.example.com/it或www.example.com/asdf,摆脱了“部门” 现在有一些内容位于/departments/路径下,因此使用以下重写规则不起作用 重写规则^/departments/(.*)$/$1[R=301,L] 因为当它重写部门下的所有内容时,部门本身被重定向回站点根目录 我

在过去的某个时候,我们的网站的结构类似于
www.example.com/departments/it
www.example.com/departments/asdf
。然后,路径变为类似
www.example.com/it
www.example.com/asdf
,摆脱了“部门”

现在有一些内容位于
/departments/
路径下,因此使用以下重写规则不起作用

重写规则^/departments/(.*)$/$1[R=301,L]

因为当它重写部门下的所有内容时,部门本身被重定向回站点根目录


我如何防止这种情况发生,以便如果我进入
www.example.com/it
它可以工作,
www.example.com/departments/it
重定向到
www.example.com/it
,如果我进入
www.example.com/departments/
,我可以得到部门信息?

粘贴此信息并尝试一下

重写规则^/departments/it$/it/$1[R=301,R,L]