简体   繁体   中英

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. 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?

You can use RedirectMatch for this task

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM