我想把這個apache重寫規則翻譯成web.config規則,但我無法讓它工作。翻譯apache重寫規則到IIS 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 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>
你是自己編寫規則,還是遵循這裏的說明:http://www.iis.net/learn/extensions/url-rewrite-module/importing-apache-modrewrite-rules – astaykov 2014-09-05 09:41:06
我正在寫作我自己的...我只有安裝了Visual Studio的IIS Express,並且找不到導入工具。 – Josef 2014-09-05 09:42:48