Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not sure whether it already exists, but you could easily write a <a href="http://www.oracle.com/technetwork/java/filters-137243.html" rel="nofollow">Filter</a> that checks whether there's a <code>Referer</code> header that matches the appropriate pattern (as described in the link you've posted).</p> <p><strong>EDIT:</strong> What <a href="http://www.dagondesign.com/articles/hotlink-protection-with-htaccess/" rel="nofollow">the article you've linked to</a> describes is a rule based on the <code>Referer</code> HTTP header (which is sent by browsers to indicate from which page the link was obtained). The following rules in <code>.htaccess</code> on Apache Httpd with <code>mod_rewrite</code> more or less mean, if the <code>Referer</code> header doesn't match the <code>http://(www\\.)?yoursite\\.com</code> pattern, then redirect to <code>/images/hotlink.jpeg</code>.</p> <pre><code>RewriteEngine on RewriteCond %{HTTP_REFERER} . RewriteCond %{HTTP_REFERER} !^http://(www\\.)?yoursite\\.com [NC] RewriteRule \\.(gif|jpe?g)$ /images/hotlink.$1 [L] </code></pre> <p>Filters are a standard mechanism in webapps for intercepting requests before they're sent to the servlet for processing (and they can chose not to redirect to the servlet if needed).</p> <p>You would override the <code>doFilter(ServletRequest request, ServletResponse response, FilterChain chain)</code> in your Filter, test whether <code>request.getHeader("Referer")</code> matches the right pattern, if so, call <code>chain.doFilter(request, response)</code>, otherwise send a redirection response to some other image (that would say "hotlink" or whatever), possibly with a 403 status code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload