M
M
Mila2020-05-29 14:42:12
htaccess
Mila, 2020-05-29 14:42:12

How to write a 301 redirect for a product category in .htaccess?

There is a website site.ru and it has the following structure https://site.ru/katalog/categoriya/podcategoriya/tovar

A redirect was made from the link:

https://site.ru/katalog/categoriya/podcategoriya1/

to

https:// site.ru/katalog/categoriya/podcategoriya2/

.htaccess has the following parameters:

RewriteCond %{REQUEST_URI} ^/katalog/categoriya/podcategoriya1/
RewriteRule ^.*$ https://site.ru/katalog/categoriya/podcategoriya2/ [R=301,L]


Everything is working. But if you follow the old link with the parameters https://site.ru/katalog/categoriya/podcategoriya1/tovar , then it is redirected to https://site.ru/katalog/categoriya/podcategoriya2/ a person does not fall into the product card, but falls into the subcategory itself. And you need to make sure that the person gets into the product card. Tell me, please, what needs to be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-05-29
@meribe

RewriteCond %{REQUEST_URI} ^/katalog/categoriya/podcategoriya1/
RewriteRule ^.*$ https://site.ru/katalog/categoriya/podcategoriya2/ [R=301,L]

Add (.*) and %1
RewriteCond %{REQUEST_URI} ^/katalog/categoriya/podcategoriya1/(.*)
RewriteRule ^.*$ https://site.ru/katalog/categoriya/podcategoriya2/%1 [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question