[英]Remove a directory from path with Regex .htaccess
I have a url: 我有一个网址:
http://www. my site .com/cms/forum/users/username/
I need it to redirect to: 我需要它重定向到:
http://www. my site .com/forum/users/username/
So the cms part of the url needs to go away. 因此,网址的cms部分需要删除。 What is my regex, and where in the folder structure do I put it?
我的正则表达式是什么?在文件夹结构中的什么位置? In other words do I add this regex to the
.htaccess
in the root of the site or in the .htaccess
in the cms
folder or someplace else? 换句话说我这个正则表达式添加到
.htaccess
在站点的根还是在.htaccess
在cms
文件夹或别的地方?
You can use RedirectMatch for this task 您可以将RedirectMatch用于此任务
RedirectMatch /cms(/.*) $1
You can also give a status to it, for example 您也可以给它一个状态,例如
RedirectMatch 301 /cms(/.*) $1
From the manual 从手册
Context: server config, virtual host, directory, .htaccess
上下文:服务器配置,虚拟主机,目录,.htaccess
This means, you can use it in your main server config, the virtual host config for your site or in the .htaccess file, wherever it fits best. 这意味着,您可以在最适合的位置在主服务器配置,站点的虚拟主机配置或.htaccess文件中使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.