.htaccess使用伪静态防止外链

不喜欢别人在他们的网页上连接自己的图片时只需要在.htaccess加入下列代码

  RewriteEngine on
  RewriteCond %{ HTTP_REFERER } !^$
  RewriteCond %{ HTTP_REFERER } !^http://(www.)?mydomain.com/.*$ [NC]
  RewriteRule .(gif&line;jpg)$ – [F]

  还有一种,实现比如引用Qzone或淘宝图片时,可以用一张图片来替代。

  RewriteEngine on
  RewriteCond %{ HTTP_REFERER } !^$
  RewriteCond %{ HTTP_REFERER } !^http://(www.)?mydomain.com/.*$ [NC]
  RewriteRule .(gif&line;jpg)$ http://www.mydomain.com/替代图片文件名 [R,L]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>