块的图像直接的联系,但保持页面显示出来 [英] Block direct link of an image but keep displaying it in pages
问题描述
可以说,我使用的是Apache和我有一样的样本Web文件夹:
Lets say I'm using Apache and I have a sample web folder like:
在此文件夹中,我有以下文件:
In this folder I have the following files:
- index.html的
- img.php
- sample.jpg
- 的.htaccess
在 index.html的
有以下的code:
<html>
<body>
<img src="sample.jpg" />
</body>
</html>
在 img.php
有以下的code:
The img.php
have the following code:
<?php
if(!isset($_GET["path"])){
exit()
}
?>
<html>
<body>
<img src="<?php echo $_GET["path"] ?>" />
</body>
</html>
我喜欢 http://myserver.com/test/sample.jpg 显示 http://myserver.com/test/img.php?path=sample的.jpg 含量 (无URL变化)
I like http://myserver.com/test/sample.jpg to show http://myserver.com/test/img.php?path=sample.jpg content (with no URL change)
很多在网上搜索后我写了下面code,但它不工作:/
After a lot of search on the net I wrote the following code but it does not work :/
RewriteEngine On
RewriteCond %{REQUEST_URI} \.(png|gif|jpe?g)$ [NC]
RewriteCond %{SCRIPT_FILENAME} \.(php|html)$ [NC]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+)$ /test/img.php?path=$1 [L]
有可能是一个!
将在第三行,但我不知道确切位置
There is probably an !
to put on the third line but I do not know exactly where
推荐答案
这种变化你的.htaccess code:
Change your .htaccess code with this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /test/
# block direct access to images
RewriteCond %{HTTP_REFERER} !^http://(www\.)?myserver\.com/ [NC]
RewriteRule ^(.+?\.(?:png|gif|jpe?g))$ img.php?path=$1 [L,NC]
这篇关于块的图像直接的联系,但保持页面显示出来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!