允许热链接,但当我是我自己的推荐人时进行重定向!
我想使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 .htaccess
您可以简化
为仅
并且可以编写该规则,就好像
您需要在参数中包含图像的路径一样。
Use .htaccess
You could simplify
to just
And the rule can be written as
if you need to include the path to the image in your parameter.
您应该使用 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]
现在,您需要检查的是引荐来源网址,因为 URL 始终是图像的 URL,因为它是 http 请求。你可以这样做:
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: