Forum: NGINX Rewrite http_referer

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
n3uro5i5 (Guest)
on 2009-03-31 01:26
(Received via mailing list)
Hi, i want to catch request from a determinate referer website and
redirect it to my root path.

I try this:

 if ($http_referer ~* "my_referer.com"){
   rewrite (.*) / redirect;
  }

But when i did't firefox say me that the request is in a neverending
loop.
So i need to rewrite the request referer header before redirect it.

I tried it like this:

 if ($http_referer ~* "my_referer.com"){
   rewrite (.*) / reset_header redirect;
  }

location /reset_header{
  proxy_set_header Referer "";
  rewrite (.*) / redirect;
}

But i don't get any results.

Any suggestion? Thanxs!!

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,651,651#msg-651
Maxim D. (Guest)
on 2009-03-31 01:46
(Received via mailing list)
Hello!

On Mon, Mar 30, 2009 at 05:16:00PM -0400, n3uro5i5 wrote:

>
>
> But i don't get any results.
>
> Any suggestion? Thanxs!!

You can't change referer, it's set by browser.  You should avoid
redirect on destination page instead.  E.g.

    location = / {
        # no redirect for /

        ...
    }

    location / {
        if ($http_referer ...) {
            rewrite ^ / redirect;
        }

        ...
    }

Maxim D.
This topic is locked and can not be replied to.