buzibuzi
buzibuzi

Reputation: 734

htaccess - redirect directory and remove matching string form end of SEF url

I want to use .htaccess to redirect directory structure and remove this string "-detail" from the end of all SEF url.

for example:

https://www.example1.com/shop/items/product-catalog/category/concrete-tiles-detail

redirect to

https://www.example2.com/product-catalog/category/concrete-tiles

The "category" part of the path is dynamic. and could even be comprised of several directories like

https://www.example1.com/shop/items/product-catalog/category1-2-or-3/sub-category/concrete-tiles-detail 

the first rule works, but i have not found a solution for removing the string at the end.i tried this answer but its not working for this scenario.

RewriteEngine On
RewriteBase /
RewriteRule ^shop/items/product-catalog/(.*) https://www.example2.com/product-catalog/$1 [R=301,L]
RewriteRule ^(.*?)="\{\{-detail(.*)$ /$1$2 [R=301,L]

Upvotes: 0

Views: 108

Answers (1)

C3roe
C3roe

Reputation: 96383

Just adding that part after the grouped match in the pattern (and anchoring the pattern at the end), should do the trick.

RewriteRule ^shop/items/product-catalog/(.*)-detail$ https://www.example2.com/product-catalog/$1 [R=301,L]

That second rule you tried, can be removed completely then.

Upvotes: 1

Related Questions