D
D
Dublerr2020-06-17 18:15:27
htaccess
Dublerr, 2020-06-17 18:15:27

How to make a 301 redirect from old pages to new ones (only the names of the directories differ)?

Good afternoon,

tell me, please, how to make a 301 redirect in the .htaccess file from the old pages of the site to the new ones. All file names are identical (digital, from one to eight digits), only the directory differs. For example:

old page
https://site.ru/old/123456

new page
https://site.ru/new/123456


If you make a redirect for each page separately, this rule works 100%:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?site\.ru [NC]
RewriteCond %{REQUEST_URI} ^/old/123456 [NC]
RewriteRule ^(.*)$ https://site.ru/new/123456 [R=301,L]


But the problem is that there are a lot of such pages - it is unrealistic to do it manually. I tried all the options - nothing works (( At best, it redirects to the main page.

There is one more remark: during development, they "forgot" to change the root page / old to / new )))
Therefore, site / old opens - a list of all site pages /new/(0-9) .

Please help, thank you all in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-06-17
@dodo512

RewriteEngine On

RewriteRule ^old/(\d+)$ https://site.ru/new/$1 [R=301,L]

Put at the beginning of the file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question