记录生活 学习SEO优化 | 他日若遂凌云志 敢笑黄巢不丈夫
>>Home > 学习笔记 > 伪静态.htaccess设置防盗链,及WordPress附件不能下载问题

伪静态.htaccess设置防盗链,及WordPress附件不能下载问题

Tags: | | 作者:海天无影

前天海天送出BLOG的第一个下载的时候,经博友提醒不能下载。海天还以为前段时间设置的伪静态.htaccess防盗链,不能直接点击下载,得另存为的原因呢(因为海天用非IE浏览器另存为的确可下载)。可发现在IE下另存为下载也不行。于是找了几个博友的看了下,他们不管什么浏览器都能正常的直接点击下载,才肯定海天BLOG的设置有问题了。最终发现是WordPress的上传目录设置原因造成的,伪静态.htaccess防盗链设置后WordPress博客不能直接下载附件。

海天在查找原因的时候也参考不少朋友的.htaccess设置,找了一个比较好的,和大家一起参考下。

RewriteEngine On
#Anti-Leech For Image
RewriteCond %{REQUEST_URI} !^/outlink
RewriteCond %{REQUEST_FILENAME} \.(gif|jpg|jpeg|png)$ [NC]
RewriteCond %{HTTP_REFERER} !^$ [NC]
RewriteCond %{HTTP_REFERER} !blog\.haitianhome\.com [NC]
RewriteCond %{HTTP_REFERER} !google\.com [NC]
RewriteCond %{HTTP_REFERER} !baidu\.com [NC]
RewriteCond %{HTTP_REFERER} !feedsky\.com [NC]
RewriteCond %{HTTP_REFERER} !yahoo\.com [NC]
RewriteCond %{HTTP_REFERER} !msn\.com [NC]
RewriteCond %{HTTP_REFERER} !feedburner\.com [NC]
RewriteRule (.*)  http://htwy.org.ru/images/logo.gif [L,NC,R]

#Anti-Leech For File
RewriteCond %{REQUEST_URI} !^/outlink
RewriteCond %{REQUEST_FILENAME} \.(rar|swf|flv|zip|exe|7z)$ [NC]
#Anti-Leech For Right Save As
RewriteCond %{HTTP_REFERER} ^$ [NC]
RewriteCond %{HTTP_REFERER} !haitianhome\.com [NC]
RewriteRule (.*)  http://htwy.org.ru/images/logo.gif [L,NC,R]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

上面就是海天的.htaccess设置,可以看出。设置把图片和附件的防盗链分开了,这样的好处是,只把图片给那些搜索引擎抓取,因为图片被抓去(比如google的图片搜索)还是能给你的BLOG带来一些流量的。但附件就算被抓去了,也带来不了流量,反而可能被下载,那实在太不划算了。

其他.htaccess设置的属性,照葫芦画瓢,大家应该不难在添加自己想要的防盗链属性,比如多给几个自己网站使用权,或者添加防盗链的文件,以上设置都能很简单的自己添加。海天就不在这里多说了,下面来说说,为什么海天之前的附件不能直接点击下载。

早在之前,海天设置后台的时候,在“设置-杂项-默认上传路径”里没有设置,保存的是默认的“wp-content/uploads”,想不到就是因为这个默认设置造成海天的BLOG设置.htaccess防盗链后,不能直接点击下载附件,下载得到的文件为“附件名.htm”。

大家只要自己设置上传路径到根目录新建一个文件夹,就可以了。

按情况来说应该不是.htaccess设置的问题,因为上传的图片都能正常显示和防盗链。所以应该就出在WordPress上传路径默认设置的问题。反正海天重新设置后防盗链及下载一切正常。

RewriteEngine On
#Anti-Leech For Image
RewriteCond %{REQUEST_URI} !^/outlink
RewriteCond %{REQUEST_FILENAME} \.(gif|jpg|jpeg|png)$ [NC]
RewriteCond %{HTTP_REFERER} !^$ [NC]
RewriteCond %{HTTP_REFERER} !blog\.haitianhome\.com [NC]
RewriteCond %{HTTP_REFERER} !google\.com [NC]
RewriteCond %{HTTP_REFERER} !baidu\.com [NC]
RewriteCond %{HTTP_REFERER} !feedsky\.com [NC]
RewriteCond %{HTTP_REFERER} !yahoo\.com [NC]
RewriteCond %{HTTP_REFERER} !msn\.com [NC]
RewriteCond %{HTTP_REFERER} !feedburner\.com [NC]
RewriteRule (.*)  http://htwy.org.ru/images/logo.gif [L,NC,R]

#Anti-Leech For File
RewriteCond %{REQUEST_URI} !^/outlink
RewriteCond %{REQUEST_FILENAME} \.(rar|swf|flv|zip|exe|7z)$ [NC]
#Anti-Leech For Right Save As
RewriteCond %{HTTP_REFERER} ^$ [NC]
RewriteCond %{HTTP_REFERER} !haitianhome\.com [NC]
RewriteRule (.*)  http://htwy.org.ru/images/logo.gif [L,NC,R]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

日志信息 »

该日志于2010-04-15 11:04由 海天无影 发表在学习笔记分类下, 你可以发表评论。除了可以将这个日志以保留源地址及作者的情况下转载到你的网站或博客,还可以通过RSS 2.0订阅这个日志的所有评论。

23条评论▼点击进行评论


  1. Warning: copy(/home/wwwroot/haitian/blog/avatar/e657612476777faf50d5f28627975291.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    晕倒,最怕看到这种类型的代码。有点费劲看不懂呢。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      说实话,我也看不懂
      不过真的能设置防盗链就醒了 :grin:


  2. Warning: copy(/home/wwwroot/haitian/blog/avatar/c7066dbe1db70fc3942d21503df04338.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    作为win主机,我看到静态链接,就郁闷。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      一般WIN的虚拟机都不行
      实在asp站长的杯具啊


  3. Warning: copy(/home/wwwroot/haitian/blog/avatar/0dcedda7123567217b5ce259e203a209.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    从来没研究过.htaccess的设置。。。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 我也没研究过
      拿来好用就是了


  4. Warning: copy(/home/wwwroot/haitian/blog/avatar/b041fec6d9b41851a84ef29a4827c1d7.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    WIN主机也可以伪静态的,只是要加些组件而已。我本地电脑搭建的都可以伪静态。
    关于防盗链,哎,我也懒得搞了,大不了每过一段时间我就改改数据库,更换一次图片地址。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      WIN主机是可以,但是一般虚拟机用户模拟让他怎么搞啊,呵呵
      有了防盗链,就在用不用经常更换地址啦
      你也加上吧,话说图片还是能带来点流量的~


  5. Warning: copy(/home/wwwroot/haitian/blog/avatar/c73866955b6bea7caaa14ebc22a7c622.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    这个倒是很实用


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 省流量的,我原来有一首MP3被百度抓取了。
      10天10G流量就没了,银子啊,哗哗的没了啊~


  6. Warning: copy(/home/wwwroot/haitian/blog/avatar/cb95657e2ccb251c905998740bb85ec6.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    我的全部是外链,防盗什么的就不必了。。。 :cool:


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 你是没被百度抓到过
      被抓到你就惨了~


      • Warning: copy(/home/wwwroot/haitian/blog/avatar/cb95657e2ccb251c905998740bb85ec6.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
        回复

        我空间上就一个博客程序 :razz:


        • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
          回复

          额 照抓,博客程序也抓……


  7. Warning: copy(/home/wwwroot/haitian/blog/avatar/c4668a51a1479f6c344c7b79636c2236.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    我的默认FEED不能read了烦


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 rss不能阅读 和htaccess设置应该没关系的吧~
      你是本身自带的RSS吗?


  8. Warning: copy(/home/wwwroot/haitian/blog/avatar/1aff72ea18f324abc5b6d0c8493a03e6.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    我也没看懂 你是搞技术的啊


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 我还没到搞技术那个层次
      这个htaccess设置防盗链 网上很多的啊


  9. Warning: copy(/home/wwwroot/haitian/blog/avatar/fb34f418df932a91d87d1304c79cc5f7.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    我才悲哀哟。WIN主机,真的气人呀!


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 WIN主机不气人
      气人的是 WIN虚拟主机 呵呵~


      • Warning: copy(/home/wwwroot/haitian/blog/avatar/fb34f418df932a91d87d1304c79cc5f7.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
        回复

        咬文嚼字嘛!


        • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
          回复

          哈哈 不过说的是事实哦
          要是你能操作服务器 不就能自己加组建了啊~


  10. Warning: copy(/home/wwwroot/haitian/blog/avatar/9e0f206193cb12d626a865adc88d9a8d.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    为什么评论时,提示WordPress错误啊?在别人的板块里


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      啊 哪个板块提示错误啊
      错误信息是什么啊
      我怎么没碰到啊~


  11. Warning: copy(/home/wwwroot/haitian/blog/avatar/8a696fb2b60f79867e39e7803303fc7a.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    发现你wordpress没玩几天,倒是玩的很专业了。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 哪是什么专业啊
      依葫芦画瓢罢了 呵呵~


  12. Warning: copy(/home/wwwroot/haitian/blog/avatar/06bc2d703214f45eae49453cd3252322.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    如果是cPanel的空间面板不知可不可以在后台直接设置,这个代码支持的确很强悍。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      CP貌似后台没找到
      不过一般都是自己设置.htacess文件的
      这个代码主要就是把图片和附件分开处理


  13. Warning: copy(/home/wwwroot/haitian/blog/avatar/152f90fdd68816e41c53dab837931b2a.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    没研究过防盗链,不过我的也是全部外链了


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      全是外链的话,那还好点。
      不过主要就是怕外链不长久
      而且一些小东西,就几K的,传到外链上,比较麻烦的啊,不如直接后台上传,呵呵


  14. Warning: copy(/home/wwwroot/haitian/blog/avatar/a941a04fe2f0165bd3274a634c6bbee7.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    谢谢共享,盗链的确实害人呀…


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      盗链的确很害人,给人盗链去了,流量一会就没了
      有个防盗链好多了~


  15. Warning: copy(/home/wwwroot/haitian/blog/avatar/0add08e212ec07498618635abac4850f.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    baidu xunlei等很猛的~~有个防盗链好多了~


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      是啊 被抓去就直接Game Over了


  16. Warning: copy(/home/wwwroot/haitian/blog/avatar/d1b6f57d60b0113d8495ce5105549db6.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    要是WP能设置上传附件到子域名的功能多好呀。

    这样搬家就方便了!


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 WP是可以的 你就在杂项里的直接设置文件的完整URL就可以了啊


  17. Warning: copy(/home/wwwroot/haitian/blog/avatar/ff042d9f1716c89d0620f4880c1c0925.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    在网上找了半天防盗链的htaccess写法,发现很多都是错误的。那些人就知道copy。还是你的实在,我复制修改了下,ok了。在此谢过。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 客气了
      我写出来的 都是自己用的通过的


  18. Warning: copy(/home/wwwroot/haitian/blog/avatar/497ea247993bf5d350c9aa7796c6eb81.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    我流量又超了 也不知道是不是这个原因


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      肯定有原因的 还是价格防盗链的好点~


  19. Warning: copy(/home/wwwroot/haitian/blog/avatar/40fb59ed03d9b0939db2144780081bb0.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    博主,怎么你自己的都没防到呢?还是没写?我的在IE下可以,在FF就不行了


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      自己美防到?什么意思?
      这个不会再火狐下不行吧?


  20. Warning: copy(/home/wwwroot/haitian/blog/avatar/40fb59ed03d9b0939db2144780081bb0.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    你的站点好像没起到作用


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 不会啊 我刚才测试了 很正常啊


  21. Warning: copy(/home/wwwroot/haitian/blog/avatar/0d6d749894ea18db5f8c92e363f946e7.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    可惜FLV视频无法防盗链 用了很多方法都不行 请指点哦 谢谢

icon_wink.gif icon_neutral.gif icon_mad.gif icon_twisted.gif icon_smile.gif icon_eek.gif icon_sad.gif icon_rolleyes.gif icon_razz.gif icon_redface.gif icon_surprised.gif icon_mrgreen.gif icon_lol.gif icon_idea.gif icon_biggrin.gif icon_evil.gif icon_cry.gif icon_cool.gif icon_arrow.gif icon_confused.gif icon_question.gif icon_exclaim.gif 

« 终于被邀请加入腾讯QQ微博,感谢真好 网络电视剧《非常爱情狂》首尾时心洁的独白 »