S
S
SmilerOFF2018-12-11 12:01:42
URL Handling
SmilerOFF, 2018-12-11 12:01:42

Mod_rewrite - How to redirect the last level folder to the first?

Please help me write a 301 redirect rule.
There is a product catalog with multi-level nesting of headings (catalogues) urls. We decided to move them to 1 nesting level. But to make it easier for Search Engines, you need to create a redirect rule.
For example:
/catalog/group1/group2/ -> /catalog/group2/
/catalog/group1/group2/group3/ -> /catalog/group3/
i.e. nesting is different and it must be brought to the same level.
Don't touch urls that end in .html
In general, I don't understand how to write RewriteCond to get the name of the last folder if it's more than 1 level of nesting.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2018-12-11
@SmilerOFF

RewriteRule ^(catalog/)([^/]+/){2,}$ /$1$2 [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question