Answer the question
In order to leave comments, you need to log in
How to make a 301 redirect extracting the name of the folder where the file is located?
Greetings colleagues! There is a non-trivial task, namely to make a redirect with the name of a folder in the domain by passing it to a variable.
For example, there is a link like site1.ru/xxx and before clicking on it, you need to redirect the user to the link site2.ru/a?link=xxx, i.e. extract the folder name from the original domain and put it in a variable to another.
Thank you!
Answer the question
In order to leave comments, you need to log in
RedirectMatch 301 ^/(.+) http://site2.ru/a?link=$1
Or
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?site1\.ru$ [NC]
RewriteRule (.+) http://site2.ru/a?link=$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^site1\.ru$
RewriteRule ^(.+)$ https://site2.ru/a\?link=$1[L,R=301]
folder name in the domain
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question