A
A
ArtemDM2020-08-18 16:56:54
htaccess
ArtemDM, 2020-08-18 16:56:54

How to mass redirect nesting pages?

Good afternoon. Who can tell me how to make a massive redirect for pages 3 and 4 of the nesting.
The site has pages 2, 3, 4 levels of nesting. And available at different URLs.
I will describe with an example.
There is a page site.ru/katalog/category1/category2 , it is available at site.ru/category1/category2 , site.ru/katalog/category2
and site.ru/category2 . You need to make it available only at the URL site.ru/katalog/category1/category2 , and all the rest redirect to it.
Who knows, tell me how to do this through htaccess, I have already tried a bunch of options, nothing works.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor Taran, 2020-08-18
@shambler81

Redirects all contents of directories
http://site.ru/any/dir1/any/any

RewriteCond %{REQUEST_URI} ^/dir1/(.*)$ 
   # если строка начинается с /dir1/ 
RewriteRule ^(.*)$ /dir1%1 [R=301,L] 
   #Перенаправить все URL с начинающиеся с dir1 на dir2 с сохранением дальнейшей структуры URL
Redirects all contents of directories with any beginning and end
http://site.ru/any/dir2/dir1
/any/any
RewriteCond %{REQUEST_URI} ^(.*)/dir1/(.*)$ 
   # если строка содержит /dir1/ 
RewriteRule ^(.*)$ %1/dir2/%2 [R=301,L] 
   #Перенаправить все URL с начинающиеся с dir1 на dir2 с сохранением дальнейшей структуры URL

A
ArtemDM, 2020-08-18
@ArtemDM

nothing changed, didn't work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question