Please help me with $http_referer

gmacar nginx-forum at forum.nginx.org
Tue Jul 11 09:40:17 UTC 2017


Hello everyone, I have read the manual
https://www.nginx.com/blog/creating-nginx-rewrite-rules/ but unfortunately I
didn't manage to solve my (simple) problem. What I need to do is: if a
visitor wants to read www.example.com/requested_page.html and comes from
Google or Bing, redirect it to a specific webpage. Example (pseudocode):

if http_referer is Google OR Bing
return https://www.example.com/other_page.html (instead of
requested_page.html)

How should I edit my current nginx.conf?
Thank you

%% Begin of nginx.conf %%

worker_processes 1;
daemon off;

error_log <%= ENV["APP_ROOT"] %>/nginx/logs/error.log;
events { worker_connections 1024; }

http {
  log_format cloudfoundry '$http_x_forwarded_for - $http_referer -
[$time_local] "$request" $status $body_bytes_sent';
  access_log <%= ENV["APP_ROOT"] %>/nginx/logs/access.log cloudfoundry;
  default_type application/octet-stream;
  include mime.types;
  sendfile on;
  gzip on;
  tcp_nopush on;
  keepalive_timeout 30;

  server {
    listen <%= ENV["PORT"] %>;
    server_name localhost;

    location ~ /\.ht { deny  all; }
    location / {
      root <%= ENV["APP_ROOT"] %>/public;
      index index.html index.htm Default.htm;
    }
    
    error_page 404 /404.html;
  }
}

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,275402,275402#msg-275402



More information about the nginx mailing list