iis图片防盗链 seo优化

本文介绍如何在IIS服务器上使用URL重写模块及.htaccess或web.config文件配置图片防盗链,允许搜索引擎抓取的同时防止图片被非法引用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.iis中安装urlrewrite重写模块 下载地址:点击链接

2.创建一个.htaccess文件

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$ [NC]
RewriteCond %{HTTP_REFERER} !google [NC]
RewriteCond %{HTTP_REFERER} !yahoo [NC]
RewriteCond %{HTTP_REFERER} !bing [NC]
RewriteCond %{HTTP_REFERER} !yourwebsiteurl.com [NC]
RewriteCond %{HTTP_REFERER} !www.yourwebsiteurl.com [NC]


RewriteRule .*.(jpg|jpeg|gif|png|bmp)$ http://www.yourwebsiteurl.com/replace_image.png [R,NC,L]


说明:

第三行到第五行功能是允许搜索引擎收录站点的图片

第六行到第七行是你的URL

最后一行功能实现禁止括号中的后缀名文件被盗用,重写为后面的图片。


或2.web.config 直接修改

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="1" stopProcessing="true">
                    <match url=".*.(jpg|jpeg|gif|png|bmp)$" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{HTTP_REFERER}" pattern="^$" negate="true" />
                        <add input="{HTTP_REFERER}" pattern="google" negate="true" />
                        <add input="{HTTP_REFERER}" pattern="yahoo" negate="true" />
                        <add input="{HTTP_REFERER}" pattern="bing" negate="true" />
                        <add input="{HTTP_REFERER}" pattern="website.com" negate="true" />
                        <add input="{HTTP_REFERER}" pattern="www.website.com" negate="true" />
                    </conditions>
                    <action type="Redirect" url="http://www.website.com/images.png" redirectType="Found" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

4.重启iis

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值