# Valid\_referers problem

**URL:** <https://www.ruby-forum.com/t/valid-referers-problem/197975>\
**Category:** NGINX\
**Created:** [October 23, 2010, 10:06pm UTC](https://www.ruby-forum.com/t/valid-referers-problem/197975 "2010-10-23T22:06:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkezSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Post date:** [October 23, 2010, 10:06pm UTC](https://www.ruby-forum.com/t/valid-referers-problem/197975/1 "2010-10-23T22:06:27Z")

</div>

I am using valid\_referers to detect image hotlinking. Invalid referers  
are forwarded to the homepage, however, I have since changed the address  
for images from [images.hollywoodgrind.com:9000](http://images.hollywoodgrind.com:9000) to  
[www.hollywoodgrind.com](http://www.hollywoodgrind.com).

The last line contains the rewrite rule ‘rewrite ^  
http://www.hollywoodgrind.com$request\_uri? permanent;’, which would  
forward traffic going to [images.hollywoodgrind.com:9000](http://images.hollywoodgrind.com:9000) to it’s new  
exact location at [www.hollywoodgrind.com](http://www.hollywoodgrind.com).

What I’d like is for invalid traffic to be forwarded to the home page  
located at [www.hollywoodgrind.com](http://www.hollywoodgrind.com), but for valid traffic to be forwarded  
to the new url location for the image.

I am not sure that the block of code below is working as I intend.

server {  
listen 9000;  
server\_name [images.hollywoodgrind.com](http://images.hollywoodgrind.com);  
location /images {  
valid\_referers blocked ~.google. ~.yahoo. ~.bing. ~.ask.  
~.live. ~.googleusercontent.com. [www.hollywoodgrind.com](http://www.hollywoodgrind.com)  
[hollywoodgrind.com](http://feeds.hollywoodgrind.com/HollywoodGrind)  
[hollywoodgrind.com](http://feeds2.feedburner.com/HollywoodGrind) [images.google.com](http://images.google.com) 209.85.171.104  
[google.com](http://google.com) [www.google.com](http://www.google.com) [yahoo.com](http://yahoo.com) [my.yahoo.com](http://my.yahoo.com)  
[feedproxy.google.com/HollywoodGrind](http://feedproxy.google.com/HollywoodGrind) [images.search.yahoo.com](http://images.search.yahoo.com) [live.com](http://live.com)  
[search.live.com](http://search.live.com) 209.85.173.132 [ask.com](http://ask.com) [images.ask.com](http://images.ask.com)  
[translate.googleusercontent.com](http://translate.googleusercontent.com) [googleusercontent.com](http://googleusercontent.com) [bing.com](http://bing.com);  
if ($invalid\_referer) {  
rewrite ^(.\*)$ [http://www.hollywoodgrind.com/](http://www.hollywoodgrind.com/);  
}  
rewrite ^ http://www.hollywoodgrind.com$request\_uri? permanent;  
}  
}

---

<div class="post-metadata">

**Author:** ![thuss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8dc957/32.png) [@thuss](https://www.ruby-forum.com/u/thuss)\
**Post date:** [October 24, 2010, 1:55am UTC](https://www.ruby-forum.com/t/valid-referers-problem/197975/2 "2010-10-24T01:55:31Z")

</div>

try  
valid\_referers blocked none allowed.dominian.tld;

2010/10/23 Todd HG [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![thuss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8dc957/32.png) [@thuss](https://www.ruby-forum.com/u/thuss)\
**Post date:** [October 24, 2010, 9:51am UTC](https://www.ruby-forum.com/t/valid-referers-problem/197975/3 "2010-10-24T09:51:50Z")

</div>

On Sat, Oct 23, 2010 at 10:06:27PM +0200, Todd HG wrote:

> What I’d like is for invalid traffic to be forwarded to the home page  
> [hollywoodgrind.com](http://feeds2.feedburner.com/HollywoodGrind) [images.google.com](http://images.google.com) 209.85.171.104  
> [google.com](http://google.com) [www.google.com](http://www.google.com) [yahoo.com](http://yahoo.com) [my.yahoo.com](http://my.yahoo.com)  
> [feedproxy.google.com/HollywoodGrind](http://feedproxy.google.com/HollywoodGrind) [images.search.yahoo.com](http://images.search.yahoo.com) [live.com](http://live.com)  
> [search.live.com](http://search.live.com) 209.85.173.132 [ask.com](http://ask.com) [images.ask.com](http://images.ask.com)  
> [translate.googleusercontent.com](http://translate.googleusercontent.com) [googleusercontent.com](http://googleusercontent.com) [bing.com](http://bing.com);  
> if ($invalid\_referer) {  
> rewrite ^(.\*)$ [http://www.hollywoodgrind.com/](http://www.hollywoodgrind.com/);  
> }  
> rewrite ^ http://www.hollywoodgrind.com$request\_uri? permanent;  
> }  
> }

server {  
listen 9000;  
server\_name [images.hollywoodgrind.com](http://images.hollywoodgrind.com);

```
location / {
    rewrite ^ http://www.hollywoodgrind.com$request_uri? permanent;
}

location /images {
    valid_referers blocked
                    ~\.google\.
                    ~\.yahoo\.
                    ...
                    googleusercontent.com
                    bing.com
                    ;

    if ($invalid_referer) {
        rewrite ^ http://www.hollywoodgrind.com/?;
    }

    rewrite ^ http://www.hollywoodgrind.com$request_uri? permanent;
}

```

}

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![thuss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8dc957/32.png) [@thuss](https://www.ruby-forum.com/u/thuss)\
**Post date:** [October 24, 2010, 8:50pm UTC](https://www.ruby-forum.com/t/valid-referers-problem/197975/4 "2010-10-24T20:50:38Z")

</div>

Thank you Igor.
