将apache重写规则转换为IIS web.config [英] Translating apache rewrite rules to IIS web.config

查看:809
本文介绍了将apache重写规则转换为IIS web.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将此apache重写规则转换为web.config规则,但我无法使其工作。

I am trying to translate this apache rewrite rule into web.config rules but I can't get it to work.

基本上它会检查用户代理并重定向提供的URL代理

Basically it checks the user agent and redirect the agent to the url provided

# 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

This is what I have so far. However, I can't figure out how to catch the url querystring parameter. Basically the text string after 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调试器进行调试

I tried with many variants of simpler rules, like redirect/rewrite when a specific user agent requests the site(in my case, the facebook crawler). But I can't even get those rules to work. I am debugging using the 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管理器(Windows 8.1上的IIS 8)将您的apache mod_rewrite规则转换为稍微不同的配置:

Not an answer but a starting point. The IIS Manager (IIS 8 on Windows 8.1) translates your apache mod_rewrite rules into this slightly different configuration:

<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>

我看到它是重写而不是重定向,但请检查这是否适用于您的方案。如果它有效,你可以开始改变它直到达到预期的结果。

I see that it is rewrite instead of redirect, but please check if this would work for your scenario. And if it works, you may begin changing it until reaching desired result.

现在我看到你的主URL匹配模式只是 urlmatchpattern 当然这不是一种模式,也是规则不起作用的根本原因。

And now I see that Your main URL Matching pattern is simply urlmatchpattern which of course is not a pattern and is the root cause for your rules to not work.

这篇关于将apache重写规则转换为IIS web.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆