重写所有图像和一个特定的 php 文件名

发布于 2024-09-16 11:29:20 字数 1371 浏览 7 评论 0原文

作为防止热链接的预防措施,我一直在使用以下规则将错误引用者重定向到我们的徽标而不是实际图像:

    #Naughty hotlinkers
    RewriteCond %{REQUEST_FILENAME} .*jpg$|.*gif$|.*png$ [NC]
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !sitedomain\.com [NC]
    RewriteCond %{HTTP_REFERER} !google\. [NC]
    RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
    RewriteRule (.*) assets/hotlinked/logo.jpg [L]

对于图像来说,它效果很好。

我正在编写可怕的包装代码,以保留嵌入在用户内容中的图像,其 src 指向一个 php 文件,该文件用于过滤请求并为我们的图像提供服务。尽管新图像将不再以这种方式提供,但我们确实需要确保以前上传的图像仍然可以从旧地址获取。

尽管图像仍然需要可访问,但该文件也需要防止热链接。

我试过这个:

    #Naughty hotlinkers
    RewriteCond %{REQUEST_FILENAME} .*jpg$|.*gif$|.*png$|.*gp2\.php.* [NC]
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !sitedomain\.com [NC]
    RewriteCond %{HTTP_REFERER} !google\. [NC]
    RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
    RewriteRule (.*) assets/hotlinked/logo.jpg [L]

但没有骰子。

我想要保护的文件在图像的 src 中使用,例如:

    http://sitedomain/legacy/gp2.php?p=long_stupid_string

请 apache 大师告诉我我在这里做错了什么愚蠢的事情?

编辑:

我在这里测试热链接预防:(

图片)这里

(php)这里

As a precaution against hotlinking, I've been using the following rule to redirect people with the wrong referrer to our logo instead of the actual image:

    #Naughty hotlinkers
    RewriteCond %{REQUEST_FILENAME} .*jpg$|.*gif$|.*png$ [NC]
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !sitedomain\.com [NC]
    RewriteCond %{HTTP_REFERER} !google\. [NC]
    RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
    RewriteRule (.*) assets/hotlinked/logo.jpg [L]

It works well, for images.

I'm in the process of writing horrible wrapping code to preserve images embedded in our user's content with their src pointing to a php file that was used to filter requests for and serve our images. Although new images will no longer be served this way, we do need to ensure previously uploaded images are still available from their old address.

Though the images still need to be accessible, this file needs to be guarded against hotlinking as well.

I tried this:

    #Naughty hotlinkers
    RewriteCond %{REQUEST_FILENAME} .*jpg$|.*gif$|.*png$|.*gp2\.php.* [NC]
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !sitedomain\.com [NC]
    RewriteCond %{HTTP_REFERER} !google\. [NC]
    RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
    RewriteRule (.*) assets/hotlinked/logo.jpg [L]

But no dice.

The file I want to protect used in image's src like:

    http://sitedomain/legacy/gp2.php?p=long_stupid_string

Please will an apache guru tell me what stupid thing I'm doing wrong here?

Edit:

I'm testing hotlink prevention here:

(image) here

(php) and here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰魂雪魄 2024-09-23 11:29:20

解决方案

    RewriteCond %{REQUEST_FILENAME} .*(jpg$|gif$|png$|gp2\.php.*) [NC]

Solution

    RewriteCond %{REQUEST_FILENAME} .*(jpg$|gif$|png$|gp2\.php.*) [NC]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文