Good evening, the essence of the question: There is a site created through wp multisite - doma.in/site1 . I want to rename it to doma.in/site2 .

How to make a 301 redirect so that all internal links are redirected to a new site in a subdirectory?

For example, to: doma.in/site1/sub1/sub2/ redirect to doma.in/site2/sub1/sub2/ .

Edits

When using the command:

 RewriteCond %{REQUEST_URI} ^.*site1.* RewriteRule ^site1/(.*)$ https://doma.in/site2/$1? [R=301,L] 

doma.in/site1/ successfully redirects to the website doma.in/site2/ . But at the same time, links like doma.in/site1/123/321/ not redirected to doma.in/site2/123/321/ . And also the link without a slash doma.in/site1 does not redirect to doma.in/site2/ .

    2 answers 2

     RewriteEngine On RewriteBase / # if request is on the old domain RewriteCond %{HTTP_HOST} ^www\.doma\.in$ RewriteRule (.*) http://www.doma.in/$1 [L,R=301] 
    • Thanks, you can clarify this code contains a redirect / site1 / to / site2 /? - Darklez
    • according to the idea, yes, check it should work - L. Vadim
    • check and if not difficult to write the result - L. Vadim
    • I’m adding a question now, as some strange redirects happen. - Darklez
    • in the address bar you write a domain so - perviy1.ru - L. Vadim

    I was able to resolve the issue (by spending all day on it) by using this code:

     RewriteEngine On RewriteCond %{HTTP_HOST} ^doma.in RewriteCond %{REQUEST_URI} ^.*site1.* RewriteRule ^site1/(.*)$ https://doma.in/site2/$1? [R=301,L]