N
N
NibiruanChild2016-01-29 14:53:58
htaccess
NibiruanChild, 2016-01-29 14:53:58

How to strip part of URL (categories/subcategories)?

There is a site on Wordpress.
I read "smart" people and set up the CNC in the
site.ru/category/page.html
format like this is better for SEO and so on. As a result, only lost positions and traffic.
Now the site has been on such CNC for several months and I want to return everything back, because I want to change the structure of the site, the names of the categories, etc. But I don't want to lose traffic, existing links, etc.
I want to do everything neatly and painlessly.
Task
There are links like:
site.ru/news/page1.html
site.ru/articles/page2.html
site.ru/about/page3.html
... It is
necessary that they be respectively
site.ru/page1.html
site.ru/ page2.html
site.ru/page3.html
I know where to change it in WP, but here’s how to properly set up a 301 redirect so that I don’t know how to write each page separately in htaccess :( There
are only a couple of categories, you can write them separately without regular expressions, if it’s easier.
UPD
I did it. enough is that right?


RedirectMatch 301 /news/(.*) site.ru/$1
RedirectMatch 301 /articles/(.*) site.ru/$1
RedirectMatch 301 /about/(.*) site.ru/$1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Иван Козлов, 2016-02-01
@trampick

есть плагин https://wordpress.org/plugins/redirection/
он поддерживает регулярные выражения. К сожалению в регулярках я не силен. Но тут может возникнуть проблема, что по урлам, которые без категорий, будет возвращаться 404 статус в заголовке. Это плохо.
Это как другой вариант решения.
Через htaccess наверное правильнее. Но тут мало кто поможет.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question