🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
直接打开文章链接和跳转文章链接的Http头是不一样的,Referer 字段来判断是否是直接访问图片。 1)创建.htaccess文件 2)防盗链规则 ### 直接打开图片链接http头信息: ~~~ Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9,en;q=0.8 Cache-Control: max-age=0 Connection: keep-alive Host: www.site.com If-Modified-Since: Tue, 22 May 2018 10:53:43 GMT If-None-Match: "19c28-56cc93b51dbc0" Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36 ~~~ ### 跳转打开图片链接信息: ~~~ Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9,en;q=0.8 Cache-Control: max-age=0 Connection: keep-alive Host: www.site.com If-Modified-Since: Tue, 22 May 2018 10:53:43 GMT If-None-Match: "19c28-56cc93b51dbc0" **区别地方->Referer: http://www.site.com/** Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36 ~~~ ### .htaccess规则配置(亲测可用) ~~~ <VirtualHost *:80> ServerAdmin chenruiqiang@yd-x.com DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs" ServerName www.site.com ServerAlias www.site.com ErrorLog "logs/www.site.com-error_log" CustomLog "logs/www.site.com-access_log" common <Directory /Applications/XAMPP/xamppfiles/htdocs> AllowOverride All Options All </Directory> <IfModule rewrite_module> RewriteEngine On RewriteCond %{REQUEST_FILENAME} \.(gif|jpeg|png|jpg)$ [NC] RewriteCond %{HTTP_REFERER} !^http://localhost/.*& [NC] RewriteRule .* /2.jpeg </IfModule> </VirtualHost> ~~~