A
A
Alexander2022-03-29 15:03:48
1C-Bitrix
Alexander, 2022-03-29 15:03:48

How to redirect via .htaccess by replacing part of the address?

There was a section
https://site/catalog/section_1/sub_sec_1/sub_sect_2/
You need to redirect to
https://site/catalog/section-sub_sect_2/

i.e. add section- and add the last section to the address.
I tried it, it doesn't work

RewriteCond %{REQUEST_URI} ^(.*)/catalog/(.*)$ 
   # если строка содержит /dir1/ 
RewriteRule ^(.*)$ %1/catalog/section-%2 [R=301,L] 
   #Перенаправить все URL с начинающиеся с dir1 на dir2 с сохранением дальнейшей структуры URL

I don't know how to add the last section

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2022-03-29
@kikher

RewriteRule ^catalog/([^/]+/){3}$ /catalog/section-$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