D
D
Dmitry2021-07-18 17:07:55
htaccess
Dmitry, 2021-07-18 17:07:55

How to redirect pages of one site to pages of another in .htaccess?

Hey!
You need to implement this 301 redirect:
site1.ru -> site2.ru
site1.ru/cat/ -> site2.ru/cat2
site1.ru/cat/item -> site2.ru/item
site1.ru/%any_other_page% - > site2.ru
etc.

That is, you need an arbitrary redirect from one URL to another, without taking into account folders, parameters, and other things, stupidly url1 -> url2, and all urls that are not specified are redirected to site2.ru.
Is it real and how to do it?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2021-07-18
@dodo512

RewriteEngine on

# site1.ru/cat/ -> site2.ru/cat2
RewriteRule ^cat/$  https://site2.ru/cat2  [R=301,L]

# site1.ru/cat/item -> site2.ru/item
RewriteRule ^cat/(.+)$  https://site2.ru/$1  [R=301,L]

# site1.ru -> site2.ru
# site1.ru/%любая_другая_страница% -> site2.ru
RewriteRule ^ https://site2.ru  [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question