我想在IIS 10中写重定向规则。我在谷歌上搜索了它,花了半天时间想出答案,但没有运气,所以我把它发了出来,以得到一些解决方案。
https://testing.app.com/apptest应该重定向到https://testing.app.com/apptest/account/loginhttps://testing.app.com/apptest/应该重定向到https://testing.app.com/apptest/account/loginhttps://test-apptest.testing.app.com/应该重定向到https://test-apptest.testing.app.com/account/loginhttps://test-apptest.testing.app.com应该重定向到https://test-apptest.testing.app.com/account/login但是当用户输入url、https://testing.app.com/apptest/account/login或https://test-apptest.testing.app.com/account/login时,它不应该重定向到任何地方,应该保持原样。
<rewrite>
<rules>
<rule name="Test1" stopProcessing="true">
<match url="account/login" />
<action type="None" />
</rule>
<rule name="Test2">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="testing.app.com" />
<add input="{REQUEST_URI}" pattern="^/apptest" />
</conditions>
<action type="Redirect" url="https://testing.app.com/apptest/account/login" appendQueryString="false" />
</rule>
</rules>
</rewrite> 发布于 2020-07-31 03:20:32
我们只需在正则表达式中添加一个锚点,以便与段‘/apptest’精确匹配。
更新的
<system.webServer>
<rewrite>
<rules>
<rule name="MyRule1" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" pattern="^((/apptest)?)/?$" />
</conditions>
<action type="Redirect" url="https://{http_host}{C:1}/account/login" />
</rule>
</rules>
</rewrite>
</system.webServer>解释
由于主机名已更改,随后将被追加到重定向URL中,因此我将其替换为{http_host}服务器变量以跟随它。此外,{Request_URI}将返回URL路径,{C:1}将返回"/apptest"或""。因此,我将其附加到重定向URL中。
每个服务器变量的含义。
最后,请不要忘记在应用规则之前安装URL重写扩展名。
https://www.iis.net/downloads/microsoft/url-rewrite
下面是Microsoft文档中正则表达式的快速引用。
如果问题仍然存在,请随时通知我。
https://stackoverflow.com/questions/63182798
复制相似问题