允许热链接,但当我是我自己的推荐人时进行重定向!

发布于 2024-08-23 10:29:25 字数 440 浏览 1 评论 0原文

我想使用 htaccess 允许热链接,但是如果有人在我的网站上查看图像,我想将他们重定向到我显示导航等的图像的“托管”版本。

因此,基本上任何从外部站点进行热链接的人都不会受影响,但如果有人直接在我的服务器上查看图像,即 www.domain.com/image.jpg 它会重定向。我还想确保我也可以在我的网站内正确显示图像。

有人可以帮忙吗?

编辑:这是我目前拥有的代码

RewriteCond %{REQUEST_FILENAME} \.jpg$
RewriteCond %{HTTP_REFERER} =""
RewriteRule ^userpics/covers/(.*).jpg$ /view/$1.html [R=301]

RewriteRule ^view/(.*).html$ /view.html?img=$1 [L]

谢谢

I want to, using htaccess, allow hotlinking BUT if someone views an image on my site I want to redirect them to a "hosted" version of the image where I display my navigation etc.

So essentially anyone hotlinking from an external site will not be affected but if someone views the image on my server directly i.e. www.domain.com/image.jpg itll redirect. I also want to make sure I can display images correctly from within my site too.

Can anyone help?

EDIT: Here is the code I currently have

RewriteCond %{REQUEST_FILENAME} \.jpg$
RewriteCond %{HTTP_REFERER} =""
RewriteRule ^userpics/covers/(.*).jpg$ /view/$1.html [R=301]

RewriteRule ^view/(.*).html$ /view.html?img=$1 [L]

Thanks

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

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

发布评论

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

评论(3

伏妖词 2024-08-30 10:29:25

使用 .htaccess

RewriteEngine on
RewriteCond %{REQUEST_URI} \.(jpg|png|gif)$
RewriteCond %{HTTP_REFERER} ^https?://yoursite\.com/.*$ [NC]
RewriteRule ([^/]+)$ url_to_script?img=$1

您可以简化

RewriteCond %{HTTP_REFERER} ^https?://yoursite\.com/.*$ [NC]

为仅

RewriteCond %{HTTP_REFERER} yoursite\.com [NC]

并且可以编写该规则,就好像

 RewriteRule (.*) url_to_script?img=$1

您需要在参数中包含图像的路径一样。

Use .htaccess

RewriteEngine on
RewriteCond %{REQUEST_URI} \.(jpg|png|gif)$
RewriteCond %{HTTP_REFERER} ^https?://yoursite\.com/.*$ [NC]
RewriteRule ([^/]+)$ url_to_script?img=$1

You could simplify

RewriteCond %{HTTP_REFERER} ^https?://yoursite\.com/.*$ [NC]

to just

RewriteCond %{HTTP_REFERER} yoursite\.com [NC]

And the rule can be written as

 RewriteRule (.*) url_to_script?img=$1

if you need to include the path to the image in your parameter.

纸短情长 2024-08-30 10:29:25

您应该使用 mod_rewrite,如果 HTTP_REFERRER 为空则重定向到 /image-with-nav.php?image=$1
尝试这样的事情
RewriteEngine 开启

RewriteCond %{HTTP_REFERER} ^$

.* image-with-nav.php?image=$1 [L]

You should use mod_rewrite, if the HTTP_REFERRER is empty then redirect to /image-with-nav.php?image=$1
Try something like this
RewriteEngine on

RewriteCond %{HTTP_REFERER} ^$

.* image-with-nav.php?image=$1 [L]

沙沙粒小 2024-08-30 10:29:25

现在,您需要检查的是引荐来源网址,因为 URL 始终是图像的 URL,因为它是 http 请求。你可以这样做:

RewriteCond %{REQUEST_FILENAME} \.(jpg|png|gif)$
RewriteCond %{HTTP_REFERER} =""
RewriteRule (.*) http://someurl.com [R=301]

Now, what you need to check is the referrer because the URL is always the URL of your image, since it is a http request. You could go with something like this:

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