[英]Translating apache rewrite rules to IIS web.config
我正在尝试将此apache重写规则转换为web.config规则,但无法正常工作。
基本上,它检查用户代理并将代理重定向到提供的URL
# 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 querystring参数。 基本上是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调试器进行调试
<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管理器(Windows 8.1上为IIS 8)将您的apache mod_rewrite规则转换为此稍有不同的配置:
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="qs/(\d*)$" ignoreCase="false" />
<conditions>
<add input="%{HTTP_USER_AGENT}" pattern="(facebookexternalhit/[09]|Twitterbot|Pinterest|Google.*snippet)" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="http://sitetocrawl.com/doc?id={R:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
我看到它是重写的,而不是重定向的,但是请检查这是否适用于您的方案。 并且,如果可行,您可以开始对其进行更改,直到获得所需的结果。
现在,我看到您的主要URL匹配模式只是urlmatchpattern
,这当然不是一个模式,并且是您的规则不起作用的根本原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.