Serj Sagan
Serj Sagan

Reputation: 30218

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?

Upvotes: 0

Views: 500

Answers (1)

Olaf Dietsche
Olaf Dietsche

Reputation: 74058

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.

Upvotes: 1

Related Questions