htaccess codes did not work
<p>This is EXACTLY the same case as: <a href="https://stackoverflow.com/questions/10236717/htaccess-how-to-prevent-a-file-from-direct-url-access">(htaccess) How to prevent a file from DIRECT URL ACCESS?</a></p>

<p>But, no one of codes provided by answers work for me. I tried 1 by 1, then tried to combine, but still not works. Here is my code:</p>

<pre><code># prevent direct image url access
# ----------
    RewriteEngine On

    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http(s)://(www\.)?example\.com [NC]
    RewriteCond %{HTTP_REFERER} !^http(s)://(www\.)?example\.com.*$ [NC]

    # this not works
    RewriteRule \.(png|gif|jpe?g)$ - [F]

    # and this
    RewriteRule \.(png|gif|jpe?g)$ - [F,NC]

    # and this
    RewriteRule \.(png|gif|jpe?g)$ https://example.com/wp-login.php [NC,R,L]

    # even by combining them
# ----------
# /prevent direct image url access
</code></pre>

<p>The case simulation:
<code>index.php</code> has <code>&lt;img src="test.png" alt=""&gt;</code> and should be normally accessible. The requirement is: <code>http://example.com/test.png</code> shouldn't be accessible.</p>

<p>I use WordPress in wp-engine, and i think WordPres's default rewrite doesn't cause the problem since the code from answers are placed above WordPress rewrite.</p>

<p><strong>UPDATE</strong></p>

<p>I use PHP Version 5.5.9-1ubuntu4.14 on Apache 2 on wp engine</p>