【发布时间】:2014-10-29 06:26:06
【问题描述】:
我正在尝试将此 apache 重写规则转换为 web.config 规则,但我无法让它工作。
基本上它会检查用户代理并将代理重定向到提供的网址
# allow social media crawlers to work by redirecting them to a server-rendered static version on the page
RewriteCond %{HTTP_USER_AGENT (facebookexternalhit/[09]|Twitterbot|Pinterest|Google.*snippet)
RewriteRule qs/(\d*)$ http://sitetocrawl.com/doc?id=$1 [P]
这是我目前所拥有的。但是,我不知道如何捕获 url 查询字符串参数。基本上是http://example.com/qs/parameter之后的文本字符串
<rule name="Social Rewrite" patternSyntax="ECMAScript" stopProcessing="true">
<match url="urltomatchpattern" ignoreCase="true" negate="false" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{HTTP_USER_AGENT}" pattern="facebookexternalhit/[0-9]|Twitterbot|Pinterest|Google.*snippet" />
</conditions>
<action type="Redirect" url="http://sitetocrawl.com/doc?parameter" appendQueryString="true" redirectType="Found" />
</rule>
编辑:
我尝试了许多更简单规则的变体,例如在特定用户代理请求站点时重定向/重写(在我的例子中是 facebook 爬虫)。但我什至无法让这些规则发挥作用。我正在使用Facebook OG debugger进行调试
<rule name="Rule1" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_USER_AGENT}" pattern="facebookexternalhit/1.1|Facebot" />
</conditions>
<action type="Redirect" url="new url here" />
</rule>
【问题讨论】:
-
您是自己编写规则,还是按照此处的说明进行操作:iis.net/learn/extensions/url-rewrite-module/…
-
我正在编写自己的...我只安装了 Visual Studio 附带的 IIS express,但没有找到导入工具。
标签: asp.net iis web-config rewrite