使用 web.config 重定向排除 robots.txt

Pri*_*gey 5 iis redirect web-config

我尝试这样做:

<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Redirect to https" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                        <add input="{REQUEST_URI}" negate="true" pattern="^/robots\.txt$" ignoreCase="true" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)

但它不起作用...我做错了什么?

Vic*_*yev 5

您的规则是正确的,很可能您的浏览器缓存了 301 重定向。您可以清除浏览器缓存并尝试访问吗robots.txt