阿帕奇的.htaccess盗链重定向 [英] Apache .htaccess hotlinking redirect

查看:192
本文介绍了阿帕奇的.htaccess盗链重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个重定向时,有人在我的网站上一个目录热链接的图像。如果有人热链接的图像,我想将它们重​​定向到一个相应的图像(相同文件名)在不同的目录。

如果有人热链接:

  

www.mydomaoin.com/PlayImages/Basic/Embedded/ {ImageName.gif}

我希望它重定向到:

  

www.mydomaoin.com/PlayImages/Basic/Shared/ {ImageName.gif}

思考?

解决方案

  RewriteEngine叙述上

#REDIRECT图像热链接
的RewriteCond%{HTTP_REFERER}!^ $
的RewriteCond%{HTTP_REFERER} ^ HTTP://(WWW \)mydomain.com /?.*$ [NC]
的RewriteCond%{REQUEST_URI} /嵌入式/(.* JPG格式(*)| *。GIF | *。PNG)$ [NC]
重写规则^(。*)$%{HTTP_HOST} / 1%/共享/%2 [R = 302,L]
 

如果引荐不为空,且引用不等于自己的域名,并且请求是在JPG / GIF / PNG结束/嵌入式文件夹中的资源,然后重写URL来替换/内嵌/共享

您可能需要修改 [R = 302] 到不同的 code ,以满足您的需求。

I am trying to create a redirection when someone hotlinks images in one directory on my site. If someone hotlinks an image, I want to redirect them to a corresponding image (same file name) in a different directory.

If someone hotlinks:

www.mydomaoin.com/PlayImages/Basic/Embedded/{ImageName.gif}

I want it to redirect to:

www.mydomaoin.com/PlayImages/Basic/Shared/{ImageName.gif}

Thoughts?

解决方案

RewriteEngine on

#redirect image hotlinks
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/?.*$ [NC]
RewriteCond %{REQUEST_URI} (.*)/Embedded/(.*jpg|.*gif|.*png)$ [NC]
RewriteRule ^(.*)$ %{HTTP_HOST}/%1/Shared/%2 [R=302,L]

If the referrer is not blank, and the referrer is not equal to your own domain, and the request is for a resource in the /Embedded folder ending in jpg/gif/png, then rewrite the url to replace /Embedded with /Shared

You may want to change the [R=302] to a different code to suit your needs.

这篇关于阿帕奇的.htaccess盗链重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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