# Hotlink protection with rewrite

**URL:** <https://www.ruby-forum.com/t/hotlink-protection-with-rewrite/181359>\
**Category:** NGINX\
**Created:** [January 10, 2010, 7:29pm UTC](https://www.ruby-forum.com/t/hotlink-protection-with-rewrite/181359 "2010-01-10T19:29:56Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![vicky007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/58956e/32.png) [@vicky007](https://www.ruby-forum.com/u/vicky007)\
**Post date:** [January 10, 2010, 7:29pm UTC](https://www.ruby-forum.com/t/hotlink-protection-with-rewrite/181359/1 "2010-01-10T19:29:56Z")

</div>

Hello,  
I moved from apache to nginx few quite busy websites and currently I  
need help with hotlink protection of swf/flt files. I can send  
hotlinking domains to 403, but I want to supply them with for example  
hotlink.swf file of my own.

I have not figured out how to rewrite the url in case of referer other  
than my own domains. Would anyone be so kind and advise me in this?

Thank you…

Vicky

Posted at Nginx Forum:

> **[hotlink protection with rewrite](https://forum.nginx.org/read.php?2,39501,39501#msg-39501)**
>
> Hello, I moved from apache to nginx few quite busy websites and currently I need help with hotlink protection of swf/flt files. I can send hotlinking domains to 403, but I want to supply them with for example hotlink.swf file of my own. I have not...

---

<div class="post-metadata">

**Author:** ![vicky007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/58956e/32.png) [@vicky007](https://www.ruby-forum.com/u/vicky007)\
**Post date:** [January 10, 2010, 7:45pm UTC](https://www.ruby-forum.com/t/hotlink-protection-with-rewrite/181359/2 "2010-01-10T19:45:09Z")

</div>

Hi !  
Something like this :

valid\_referers none blocked domain.tld www.domain.tld;

location /flv/  
{  
if ($invalid\_referer) {  
rewrite ^ /path/to/hotlink.flv last;  
}  
}

On Mon, Jan 11, 2010 at 1:29 AM, vicky007 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello,  
> I moved from apache to nginx few quite busy websites and currently I need help with hotlink protection of swf/flt files. I can send hotlinking domains to 403, but I want to supply them with for example hotlink.swf file of my own.
> 
> I have not figured out how to rewrite the url in case of referer other than my own domains. Would anyone be so kind and advise me in this?
> 
> Thank you..
> 
> Vicky

–  
Aleksej Besciokov  
EMail/JID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
phone: +7 495 7853149

---

<div class="post-metadata">

**Author:** ![vicky007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/58956e/32.png) [@vicky007](https://www.ruby-forum.com/u/vicky007)\
**Post date:** [January 10, 2010, 9:07pm UTC](https://www.ruby-forum.com/t/hotlink-protection-with-rewrite/181359/3 "2010-01-10T21:07:41Z")

</div>

location ~ .(jpg|jpeg|png|gif)$ {  
valid\_referers server\_names blocked none;  
if ($invalid\_referer) {  
rewrite ^(.\*)$ /hotlink.png break;  
}  
}

I using something like it.

---

<div class="post-metadata">

**Author:** ![vicky007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/58956e/32.png) [@vicky007](https://www.ruby-forum.com/u/vicky007)\
**Post date:** [January 10, 2010, 9:31pm UTC](https://www.ruby-forum.com/t/hotlink-protection-with-rewrite/181359/4 "2010-01-10T21:31:06Z")

</div>

Thank you very much, it works perfectly.

vicky

Posted at Nginx Forum:

> **[Re: hotlink protection with rewrite](https://forum.nginx.org/read.php?2,39501,39531#msg-39531)**
>
> Hello, I moved from apache to nginx few quite busy websites and currently I need help with hotlink protection of swf/flt files. I can send hotlinking domains to 403, but I want to supply them with for example hotlink.swf file of my own. I have not...

---

<div class="post-metadata">

**Author:** ![vicky007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/58956e/32.png) [@vicky007](https://www.ruby-forum.com/u/vicky007)\
**Post date:** [January 31, 2010, 1:48pm UTC](https://www.ruby-forum.com/t/hotlink-protection-with-rewrite/181359/5 "2010-01-31T13:48:16Z")

</div>

Samfingcul, I did it as other members here advised me. Try it…

Posted at Nginx Forum:

> **[Re: hotlink protection with rewrite](https://forum.nginx.org/read.php?2,39501,48098#msg-48098)**
>
> Hello, I moved from apache to nginx few quite busy websites and currently I need help with hotlink protection of swf/flt files. I can send hotlinking domains to 403, but I want to supply them with for example hotlink.swf file of my own. I have not...

---

<div class="post-metadata">

**Author:** ![vicky007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/58956e/32.png) [@vicky007](https://www.ruby-forum.com/u/vicky007)\
**Post date:** [January 30, 2010, 5:52pm UTC](https://www.ruby-forum.com/t/hotlink-protection-with-rewrite/181359/6 "2010-01-30T17:52:07Z")

</div>

@vicky007 - hey. can you please tell me how you done it ? thanks

Posted at Nginx Forum:

> **[Re: hotlink protection with rewrite](https://forum.nginx.org/read.php?2,39501,47724#msg-47724)**
>
> Hello, I moved from apache to nginx few quite busy websites and currently I need help with hotlink protection of swf/flt files. I can send hotlinking domains to 403, but I want to supply them with for example hotlink.swf file of my own. I have not...

---

<div class="post-metadata">

**Author:** ![vicky007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/58956e/32.png) [@vicky007](https://www.ruby-forum.com/u/vicky007)\
**Post date:** [July 16, 2011, 1:40pm UTC](https://www.ruby-forum.com/t/hotlink-protection-with-rewrite/181359/7 "2011-07-16T13:40:21Z")

</div>

None of the above methos has helped me.  
My files are .swf and .mp4 .  
Here is an example of my conf

valid\_referers none blocked [mysite.com](http://mysite.com);  
location /home/tophi/www/files/  
{  
if ($invalid\_referer) {  
rewrite ^ /home/tophi/www/images/hl.png last;  
}  
}

location ~ .(swf|mp4)$ {  
valid\_referers server\_names blocked _.mysite.com;  
if ($invalid\_referer) {  
rewrite ^(._)$ /home/tophi/www/images/hl.png break;  
}  
}

please advice  
thanks

Posted at Nginx Forum:

> **[Re: hotlink protection with rewrite](https://forum.nginx.org/read.php?2,39501,212475#msg-212475)**
>
> Hello, I moved from apache to nginx few quite busy websites and currently I need help with hotlink protection of swf/flt files. I can send hotlinking domains to 403, but I want to supply them with for example hotlink.swf file of my own. I have not...

---

<div class="post-metadata">

**Author:** ![vicky007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/58956e/32.png) [@vicky007](https://www.ruby-forum.com/u/vicky007)\
**Post date:** [July 17, 2011, 3:07pm UTC](https://www.ruby-forum.com/t/hotlink-protection-with-rewrite/181359/8 "2011-07-17T15:07:24Z")

</div>

Try this:

location ~ .(swf|mp4)$ {  
valid\_referers server\_names blocked _.mysite.com;  
if ($invalid\_referer) {  
rewrite ^(._)$ /hl.png break;  
}  
}

location =/hl.png {  
root /home/tophi/www/images;  
}

2011/7/16 tophi [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![vicky007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/58956e/32.png) [@vicky007](https://www.ruby-forum.com/u/vicky007)\
**Post date:** [July 17, 2011, 3:33pm UTC](https://www.ruby-forum.com/t/hotlink-protection-with-rewrite/181359/9 "2011-07-17T15:33:24Z")

</div>

So not I’m not able to direct download the file, but videos also can not  
be started from the website’s player. I have changed \*.mysite.com; also  
with [mysite.com](http://mysite.com) and [www.mysite.com](http://www.mysite.com), same result

Try this:

location ~ .(swf|mp4)$ {  
valid\_referers server\_names blocked _.mysite.com;  
if ($invalid\_referer) {  
rewrite ^(._)$ /hl.png break;  
}  
}

location =/hl.png {  
root /home/tophi/www/images;  
}

2011/7/16 tophi [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Posted at Nginx Forum:

> **[Re: hotlink protection with rewrite](https://forum.nginx.org/read.php?2,39501,212485#msg-212485)**
>
> Hello, I moved from apache to nginx few quite busy websites and currently I need help with hotlink protection of swf/flt files. I can send hotlinking domains to 403, but I want to supply them with for example hotlink.swf file of my own. I have not...

---

<div class="post-metadata">

**Author:** ![vicky007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/58956e/32.png) [@vicky007](https://www.ruby-forum.com/u/vicky007)\
**Post date:** [July 18, 2011, 5:39am UTC](https://www.ruby-forum.com/t/hotlink-protection-with-rewrite/181359/10 "2011-07-18T05:39:40Z")

</div>

try this :

location ~ .(swf|mp4)$ {  
valid\_referers server\_names _.mysite.com;  
if ($invalid\_referer) {  
rewrite ^(._)$ /hl.png break;  
}  
}

location =/hl.png {  
root /home/tophi/www/images;  
}

or you can try this one

location ~ .(swf|mp4)$ {  
valid\_referers server\_names none _.mysite.com;  
if ($invalid\_referer) {  
rewrite ^(._)$ /hl.png break;  
}  
}

location =/hl.png {  
root /home/tophi/www/images;  
}

hope it useful 🙂
