Answer the question
In order to leave comments, you need to log in
How to redirect from one url to another in nginx?
How to make the following redirection in nginx:
from site.ru to newsite.ru
from site.ru/page to newsite.ru/new/page
The option I use does not work:
server {
listen 80;
server_name site.ru;
location / {
rewrite ^(.*) newsite.ru/$1 permanent;
}
location /page {
rewrite ^(.*) newsite.ru/new/page/$1 permanent;
}
}
UPD: I noticed such a strange thing, above in the config I have a redirect from old.site.ru to newsite.ru/old/, so now with the redirect that I described above opens: newsite.ru/old/new/page/, then there is, as I understand it, a redirect occurs, only the name of the nginx server is substituted from the previous redirect.
There is an opinion that regular expressions should help in this case, but how to use them correctly for this specific config does not fit in my head.
Answer the question
In order to leave comments, you need to log in
So try:
server_name old.site.ru www.old.site.ru;
location / {
rewrite ^(.*)$ http://newsite.ru/old/$1 permanent;
}
}
server {
server_name site.ru;
rewrite ^ http://newsite.ru$request_uri? permanent;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question