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.

有帮助吗?

解决方案 2

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;
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top