I
I
Ivan Ilyasov2021-04-26 15:41:52
Apache HTTP Server
Ivan Ilyasov, 2021-04-26 15:41:52

How to redirect to an address that includes the parent category only if it doesn't exist?

I set up redirection via .htaccess mod_rewrite from one CMS to a new one.
On the old site, some URLs look like:
https://site.ru/subcategory/tovar-artikul-1
This whole thing needs to be redirected to

https://site.ru/parent-category/subcategory/tovar-artikul-1

Yes, despite the fact that there is no cyclic redirection when you go to existing links of the form https://site.ru/parent-category/subcategory.
That is, if there is a parent-category , then it is not necessary to redirect, if not, then it is necessary to redirect to the address with parent-category

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2021-04-26
@IvanIlyasov

RewriteRule ^subcategory/.+$ https://site.ru/parent-category/$0 [R=301,L]

Put at the beginning of the file immediately after RewriteEngine on

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question