A
A
Alexander Karpov2016-11-09 18:52:12
Nginx
Alexander Karpov, 2016-11-09 18:52:12

How to do such a rewrite in nginx?

I want to make such a redirect, I read that in nginx you can use the $request_uri variable (directive), I tried to do this:

server{
   server_name www.site1.ru;
   if($request_uri != robots.txt){
       rewrite ^(.*) http://www.site2.ru$1 permanent;
   }
}

Tell me how to use request in this context, or how best to implement such a redirect? Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Nemiro, 2016-11-09
@Inkognitoss

Most likely it will be something like this:

if ($request_uri ~ "^/robots.txt") {
# или
# if ($request_uri != "robots.txt") {
  rewrite ^(.*) http://www.site2.ru$1 permanent;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question