问题描述
有一个大的图像GALERIE需要盗链脚本白名单的谷歌,必应,雅虎等。在网络上,我发现很多的例子,但他们都不同的语法。
例1:
的RewriteCond%{HTTP_REFERER} ^ HTTP://(。+ \)谷歌/.*$ [NC]
例2:
的RewriteCond%{HTTP_REFERER}!谷歌\。 [NC]
例3:
的RewriteCond%{HTTP_REFERER}!谷歌。 [NC]
示例4:
SetEnvIfNoCase的Referer^(HTTP | HTTPS)://.*google.*白名单
例5:
的RewriteCond%{HTTP_REFERER} ^ HTTP://(。+ \)谷歌/.*$ [NC]
问题1:哪一个是最快的,正确与域通配符
?问题2:为什么在例如5地址为http://盈的时候不需要的
我所做
的RewriteCond%{HTTP_REFERER}!我的域\。 [NC]
的RewriteCond%{HTTP_REFERER}!搜索\ Q =缓存[NC]
的RewriteCond%{HTTP_REFERER}!谷歌\。 [NC]
的RewriteCond%{HTTP_REFERER}!微博\。 [NC]
的RewriteCond%{HTTP_REFERER}!Facebook的\。 [NC]
的RewriteCond%{HTTP_REFERER}!googleusercontent \。 [NC]
的RewriteCond%{HTTP_REFERER}!兵\。 [NC]
的RewriteCond%{HTTP_REFERER}!Pinterest的\。 [NC]
的RewriteCond%{HTTP_REFERER}!雅虎\。 [NC]
的RewriteCond%{REQUEST_URI}!^ /盗链\ .JPG $ [NC]
重写规则\(GIF | JPG | PNG)$ HTTP://domain.tld/hotlink.jpg [R,NC,L]
问题3:是否有更快的只有1号线?我怎么能写像这样的:
谷歌| Facebook的|冰|等
我所做的:
的RewriteCond%{HTTP_REFERER}!我的域\。 [NC]
的RewriteCond%{HTTP_REFERER}(谷歌| googleusercontent |雅虎|冰| Facebook的| Pinterest的。|等)![NC]
的RewriteCond%{REQUEST_URI}!^ /盗链\ .JPG $ [NC]
重写规则\(GIF | JPG | PNG)$ HTTP://my-domain.tld/hotlink.jpg [R,NC,L]
那么不是真的,科学的,但我的猜测是OR操作办法是最长的。
我做了 http://www.regex101.com 试试这个正则表达式:(谷歌| googleusercontent |雅虎|冰| Facebook的| Pinterest的)
来匹配 http://www.yahoo.com
它花了87步(你可以看到它在该网站正则表达式调试器),它tooks只有7个步骤,以配合正则表达式是雅虎
所以大约7 9(RewriteCond指令数)给予63步,其中或运算的正则表达式了87步,所以我认为它会使用简单的正则表达式和多重的RewriteCond直到步骤交叉在任何情况下更快(正则表达式意志花了步骤predictable数量,尝试用完整的执行或运算,最后一场比赛要知道最大的步骤)。
再次:没有科学的存在和myabe它会花费更多的时间要求9测试比一个复杂的,也许在调试模式下的Apache能告诉所花费的时间,但我不能确定
它仍然选择preFER一个比其他的问题,我敢肯定它不会做前serer已被请求的次数反正陷入僵局一个noticable差别。
有关比赛的域\。
是足够多的,没有必要使用更复杂的东西在我看来,也许你可能会得到一些边缘情况下,有域。
...
在 \
之前的点是非常重要的匹配litteral点,而不是任何字符的正则表达式域
之后
A big image galerie need a hotlinking script with a whitelist for google, bing, yahoo etc.On the web I found many examples but they have all a different syntax.
Example 1:
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?google/.*$ [NC]
Example 2:
RewriteCond %{HTTP_REFERER} !google\. [NC]
Example 3:
RewriteCond %{HTTP_REFERER} !google. [NC]
Example 4:
SetEnvIfNoCase Referer "^(http|https)://.*google.*" whitelist
Example 5:
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?google/.*$ [NC]
Question 1: Which one is the fastest and correct with a domain wildcard?
Question 2: Why is on example 5 a http:// infront when its not needed?
What I did:
RewriteCond %{HTTP_REFERER} !my-domain\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !twitter\. [NC]
RewriteCond %{HTTP_REFERER} !facebook\. [NC]
RewriteCond %{HTTP_REFERER} !googleusercontent\. [NC]
RewriteCond %{HTTP_REFERER} !bing\. [NC]
RewriteCond %{HTTP_REFERER} !pinterest\. [NC]
RewriteCond %{HTTP_REFERER} !yahoo\. [NC]
RewriteCond %{REQUEST_URI} !^/hotlink\.jpg$ [NC]
RewriteRule \.(gif|jpg|png)$ http://domain.tld/hotlink.jpg [R,NC,L]
Questions 3: Is it faster to have only 1 line? How can I write it such as this:
google|facebook|bing|etc
What I did:
RewriteCond %{HTTP_REFERER} !my-domain\. [NC]
RewriteCond %{HTTP_REFERER} !(google|googleusercontent|yahoo|bing|facebook|pinterest|etc.) [NC]
RewriteCond %{REQUEST_URI} !^/hotlink\.jpg$ [NC]
RewriteRule \.(gif|jpg|png)$ http://my-domain.tld/hotlink.jpg [R,NC,L]
Well not really scientific but my guess is the ored option would be longest.
I did a try on http://www.regex101.com with this regex: (google|googleusercontent|yahoo|bing|facebook|pinterest)
to match http://www.yahoo.com
It took 87 steps (you can see it in regex debugger on the site) where it tooks only 7 steps to match with a regex which is yahoo
So roughly 7 by 9 (number of RewriteCond) give 63 steps where the ored regex took 87 steps, so I think it would be faster in any case using simple regex and multiple RewriteCond until the steps cross (the regex will took a predictable number of steps, try it with the full ored and the last match to know the maximum steps).
Once again: nothing scientific there and myabe it would take more time calling 9 test than a complex one, maybe a apache in debug mode could tell the time taken but I'm unsure.
It's still a matter of choice to prefer one over the other, as I'm quite sure it won't do a noticable difference before the serer has stalled anyway by the number of requests.
For the match the domain\.
is enought, no need to use something more complex in my opinion, maybe you may got some edge cases where there's domain.
elsewhere in the referer...
The \
before the dot is important to match a litteral dot and not any char after domain
in the regex.
这篇关于停止图像白名单htaccess的盗链的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!