Question

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.

Was it helpful?

Solution 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

OTHER TIPS

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;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top