是否可以在ASP.NET/IIS中依赖于用户代理进行条件URL重写?

Che*_*aks 6 c# asp.net iis iis-7 url-rewriting

我工作的网站主持内容不断被抓取并张贴在其他地方.

是否可以进行URL重写,以便普通用户和列入白名单的抓取工具可以查看网站,但阻止访问无法识别的浏览器?

Laz*_*One 11

是的,你可以使用URL Rewrite模块(我正在使用v2 ..但它也应该与v1.x一起使用,尽管我没有v1.x可以测试):

<system.webServer>
    <rewrite>
        <rules>
            <rule name="UserAgentRedirect" stopProcessing="true">
                <match url="^(.*)$" />
                <conditions>
                    <add input="{HTTP_USER_AGENT}" pattern="(iphone|ipod)" />
                </conditions>
                <action type="Rewrite" url="/special-page.aspx" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

根据上述规则,来自iPhone或iPad(或具有iphoneipod在用户代理字符串中的任何其他浏览器/应用程序)的所有请求都将被重写(内部重定向)到/special-page.aspx.