[英]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.