如何使直接图像访问htaccess的重定向,同时允许嵌入 [英] How to make htaccess redirect on direct image access while allowing embedding

查看:97
本文介绍了如何使直接图像访问htaccess的重定向,同时允许嵌入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该方案是这样的,说我有一个包含一些图片网站。我希望让人们将它们嵌入到自己的网站,但我也希望,当有人试图直接访问图像重定向。

The scenario looks like this, say that I have a website that contains some images. I want to allow people to embed them on their site, but I also want to redirect when anybody tries to access the image directly.

一种选择是这样的

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?imgzzz.com/.*$ [NC]
RewriteRule i/image_(\d+)\.(jpg|gif) - [F]

这将拒绝来自其他地方的任何访问比的部位,但不允许嵌入图像。

which would deny any access from anywhere else than the site, but that doesn't allow embedding the image.

第二个选项是ommit第二的RewriteCond 只留下

The second option is to ommit the second RewriteCond leaving only

RewriteCond %{HTTP_REFERER} !^$
RewriteRule i/image_(\d+)\.(jpg|gif) - [F]

允许嵌入,但用户仍然可以访问图像,如果他从其他地方正在添加不是一个书签。

Which allows embedding, but the user can still access the image if he's comming from anywhere else than a bookmark.

有没有什么办法,使嵌入可用,并在同一时间做重定向直接访问图像?

推荐答案

下面是一个解决方案

RewriteCond %{HTTP_REFERER} !^http://(www\.)?imgzzz.com/.*$ [NC]
RewriteRule i/image_(\d+)\.(jpg|jpeg|gif) pic/$1 [L]

这篇关于如何使直接图像访问htaccess的重定向,同时允许嵌入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆