Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Htaccess remove string from URL

We've currently moved our site to a new server but re-formatted the menu item links.

The previous ones were:

www.example.com/products/module-home/something.html

and now they are:

www.example.com/products/something.html

What I would like to do is, if a user tried to visit a page which contains module-home in the URL, it will simply remove it and redirect them to the URL without it. Would the following RewriteRule rule be the best approach for this?

RewriteRule ^module-home/(.*)$ /$1 [L,R=301]

I know Joomla has it's own redirect manager built into the backend, however performance wise, I think modifying the .htaccess file would be better, however correct me if I'm wrong.

like image 575
Lodder Avatar asked Aug 07 '14 13:08

Lodder


1 Answers

Assuming your htaccess is in the root folder, you can put this rule in first position (right after RewriteEngine on or RewriteBase line)

RewriteRule ^([^/]+)/module-home/?(.*)$ /$1/$2 [R=301,L]
like image 188
Justin Iurman Avatar answered Oct 19 '22 15:10

Justin Iurman