Answer the question
In order to leave comments, you need to log in
How to make a redirect with multiple htaccess conditions?
The essence is this:
There are 3 sites: let's say site1, site2, site3. Site1 wants to cease to exist, and in order to transfer the link weight, redirects must be made from it. From the main page of site1, you need to redirect to the main page of site2, ironically. And from the specified internal sections (for example, site1/catalog/plitka/) it should redirect to sections of the site3 directory (for example, to site3/catalog/plitka-uzor/). The difficulty is that it is not possible to make all the conditions work at once. What htaccess looks like now:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
#перенаправление с site1 на site2
RewriteCond %{HTTP_HOST} ^site1\.ru
RewriteRule ^(.*)$ https://site2.ru/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.site1\.ru
RewriteRule ^(.*)$ https://site2.ru/$1 [R=301,L]
#перенаправление с конкретных урл site1 на конкретные урлы site3
RewriteCond %{REQUEST_URI} ^/catalog/krovlya/gibkaya_cherepitsa_/$
RewriteRule ^(.*)$ https://site3.ru/catalog/krovlya/gibkaya-cherepitsa/? [R=301,L]
RewriteCond %{REQUEST_URI} ^/catalog/krovlya/$
RewriteRule ^.*$ https://site3.ru/catalog/krovlya/? [R=301,L]
RewriteCond %{REQUEST_URI} ^/catalog/krovlya/profnastil/$
RewriteRule ^.*$ https://site3.ru/catalog/krovlya/profnastil/? [R=301,L]
</IfModule>
Answer the question
In order to leave comments, you need to log in
RewriteCond %{HTTP_HOST} ^(www\.)?site1\.ru$
RewriteRule ^$ https://site2.ru/ [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?site1\.ru$
RewriteRule ^catalog/krovlya/(profnastil/)?$ https://site3.ru/$0? [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?site1\.ru$
RewriteRule ^catalog/krovlya/gibkaya_cherepitsa_/$ https://site3.ru/catalog/krovlya/gibkaya-cherepitsa/? [R=301,L]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question