如何使直接图像访问htaccess的重定向,同时允许嵌入重定向、图像、直接、htaccess

2023-09-02 11:41:12 作者:无欲无求

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

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]