how to block hotlinking for my media files?

I have swf& images files that can be hotlinked from otherwebsites like in this question How can I use HTTP Referer header to have my swf files viewed only from my website ?

EDIT

My files are hosted at my server, I am not using Amazon S3 service, or other files hosting services.

Answers


if request.env['HTTP_REFERER'] =~ /yourdomain\.com\//
  # serve asset
end

Note that nil =~ regex # => nil so you don't need to check if request.env['HTTP_REFERER'] exists first.

Edit:

More about the =~ operator: Object#=~, String#=~, Regex#=~

$ irb
> nil =~ /something/
=> nil

You should assure that referrer link has same domain as yours, like if you have nginx:

location ~* (\.swf)$ {
    valid_referers blocked mydomain.com www.mydomain.com;
    if ($invalid_referer) ) {
        return 444;
    }
}

Need Your Help

Binary Converter For Loop Trouble

javascript string for-loop binary converter

So I am making a binary converter for science project and I am having a bit of difficulty.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.