我在下面有我的重写规则,但是我不明白为什么我的第二条规则不起作用。当我禁用第一个时,它将正常工作。如果两个规则的网址完全相同,是否有限制?请注意,在第一个条件下,如果百度蜘蛛抓取了我们的网站,我将尝试将请求映射到NuxtJS;否则,只需在wwwroot目录中提供静态HTML文件即可
<?xml version="1.0" encoding="UTF-8"?>
<rules>
<clear />
<rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="false">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:3000/{R:1}" />
<conditions>
<add input="{HTTP_USER_AGENT}" pattern="^((?Baidu).)*$" />
</conditions>
</rule>
<rule name="StaticHTMLForBaiduCrawler" enabled="true" stopProcessing="false">
<match url="(.*)" />
<conditions>
<add input="{HTTP_USER_AGENT}" pattern="^((?!Baidu).)*$" />
</conditions>
<action type="Rewrite" url="{R:1}/index.html" />
</rule>
</rules>
答案 0 :(得分:1)
没有这样的限制。
您的第一个模式在语法上无效,因此会发生错误。
表达式“ ^((?Baidu)。)* $”的语法无效。
由于您不需要完全匹配,因此像Baidu
这样的简单模式就可以使用。查看以下规则,并注意negate="true"
。
<rules>
<clear />
<rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:3000/{R:1}" />
<conditions>
<!-- if user agent contains Baidu -->
<add input="{HTTP_USER_AGENT}" pattern="Baidu" />
</conditions>
</rule>
<rule name="StaticHTMLForBaiduCrawler" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<!-- if user agent does not contain Baidu -->
<add input="{HTTP_USER_AGENT}" pattern="Baidu" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}/index.html" />
</rule>
</rules>