Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are two things you can do:</p> <p>1- no redirect if the query comes from the server You just have to add a RewriteCond directive before the RewriteRule, which says that the following RewriteRule is not to be done if the source of the http query is this server.</p> <pre><code>RewriteCond %{REMOTE_ADDR} !127.0.0.1 </code></pre> <p>Depending on how your script does the get, you may need to use instead your server's private IP. Or add another RewriteCond with this IP, to prevent both to be redirected.</p> <p>2- you can also prevent redirect depending on the referer of the query, but you have to be sure that it is sent with the query. (referer is the source URL that requested your URL. For example, if you're on <a href="http://localhost/index.php" rel="nofollow">http://localhost/index.php</a> and click a link to <a href="http://localhost/help.php" rel="nofollow">http://localhost/help.php</a>, the referer of the last one will be <a href="http://localhost/index.php" rel="nofollow">http://localhost/index.php</a>). You still use a RewriteCond, but with HTTP_REFERER instead of REMOTEHOST.</p> <p>eg:</p> <p><del> RewriteCond %{HTTP_REFERER} !showimage.php</del></p> <pre><code>RewriteCond %{HTTP_REFERER} !/images/.*\.png </code></pre> <p>You may have to toy a bit with the full referer, not user if this is enough, but just the idea to start with. You can check which referer you have in the access log (if you have %{Referer}i enabled in the LogFormat you use)</p> <p>Got it : problem was that, the REFERER is the URL that was asked, and not the rewritten one (should I've thought about it, it's obvious). So, the problem is that when you require <a href="http://localhost/images/x.png" rel="nofollow">http://localhost/images/x.png</a>, it is rewritten as <a href="http://localhost/showimage.php?image=x.png" rel="nofollow">http://localhost/showimage.php?image=x.png</a> which serves the page with the inside. BUT the referer is NOT showimage.php but .../images/x.png (the initial URL). So, the RewriteCond on the HTTP_REFERER must check that the origin URL is something like /images/*.png instead. </p> <p>Here is my working example. Rules are in [DOCROOT]/.htaccess file:</p> <pre><code>RewriteEngine on RewriteCond %{HTTP_REFERER} !/images/.*\.png RewriteRule ^images/([A-Za-z1-9-]+).png$ image.php?name=$1 [L] </code></pre> <p>Here is my image.php file:</p> <pre><code>&lt;html&gt; Here it is : &lt;img src="/images/&lt;?php echo $_GET['name']; ?&gt;.png"/&gt; &lt;/html&gt; </code></pre> <p>With my browser, calling http://[server ip]/images/foo.png will display an html page, containing the words "Here it is : " AND the requested picture, taken from [DOCROOT]/images/foo.png. </p> <p>For the "not from this server" to work, you just add the previous RewriteCond about REMOTE_ADDR before the RewriteRule (when you don't specify [OR], they work as AND conditions - the rewriterule is triggered only if both conditions are true - not from this server and not from the php script)</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