I
I
ivan_troshkin2018-02-28 12:15:16
PHP
ivan_troshkin, 2018-02-28 12:15:16

Remove part of url via htaccess or php?

Help me cut out part of the URL...
There are duplicates on the site:
site.ru/categories/categories-name/article1
site.ru/article1
How to remove /categories/categories-name/ from the link in .htaccess or php
to the output turned out to be site.ru/article1
but the content would be loaded from site.ru/categories/categories-name/article1
New articles are often added to the site, so manually redirecting each URL each time is not an option.
Is it possible to make such a universal redirect that simply automatically removes the extra from the middle of the link?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2018-02-28
@shambler81

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question