Rewrite http_referer


#1

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


#2

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.