S
S
Sys3X2020-08-27 00:10:06
Nginx
Sys3X, 2020-08-27 00:10:06

How to redirect search engine to HTML file using nginx?

Friends, please help me with this question.
I want search engines to see a specific file.html page , while the user sees a regular site. At the same time, you need to save access to robots.txt - this is exactly what I did, but when the search engine enters the main nginx, it gives a 500 error:

[error] 13833#0: *1 rewrite or internal redirection cycle while processing "/file.html",

server {
  access_log /var/log/nginx/access.log main;
  error_log  /var/log/nginx/vhost-error_log warn;
  listen 80;
  listen 443;
  server_name www.site.biz site.biz;
 
  location / {

# Если поисковик - присваиваем значение T
if ($http_user_agent ~* ".*Googlebot.*"){
    set $RW T;
}

# Если в запросе robots.txt - не перенаправлять, значение F

if ($request_uri ~ .*.robots.*) {
     return 200 "User-agent: *\nAllow: /\nHost: https://www.site.biz";
    set $RW F;
    }

# Если другой запрос - направляем на file.html. Именно эта строка реврайта вызывает ошибку!

    if ($RW = T)
{
rewrite ^ /file.html;
}


   error_page 503 /503.html;
   error_page 500 /500.html;
   client_max_body_size    10m;
   client_body_buffer_size 128k;

   proxy_send_timeout   90;
   proxy_read_timeout   90;

   proxy_buffer_size    4k;
   proxy_buffers 80 32k;
   proxy_busy_buffers_size 64k;
   proxy_temp_file_write_size 64k;
   proxy_connect_timeout 10s;

   proxy_redirect  off;

   proxy_pass   http://127.0.0.1:8083;

   proxy_set_header   Host   $host;
   proxy_set_header   X-Real-IP  $remote_addr;
   proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
}
}


What am I doing wrong?
Thank you all and hope you can help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sys3X, 2020-08-27
@Sys3X

Understood.
It was necessary like this:
rewrite ^ /file.html break;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question