windows - 如何使用 web.config 覆盖同名但扩展名不同的文件的重定向规则?
问题描述
我有一个现有的 web.config 文件来将标题为 privacy.asp 的页面重定向到隐私(没有 .asp 扩展名)。它可以正常工作。
我现在有一个客户,他有一个文件privacy.html,我想发送一个永久的httpResponseStatus,即/privacy。
这是我尝试过的,但是当拉起privacy.html时,它会使用.html扩展名解析,但实际页面是.asp的页面。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<location path="privacy.html">
<system.webServer>
<httpRedirect enabled="true" destination="/privacy/" httpResponseStatus="Permanent" />
</system.webServer>
</location>
<system.webServer>
<rewrite>
<rules>
<rule name="privacy" stopProcessing="true">
<match url="^privacy" />
<action type="Rewrite" url="privacy.asp" />
</rule>
</rules>
</system.webServer>
</configuration>
解决方案
您可以使用以下重写规则:
<rule name="privacy" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="privacy.html$" />
</conditions>
<action type="Redirect" url="privacy" appendQueryString="false" />
</rule>
<rule name="rewrite rule" stopProcessing="true">
<match url="privacy$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="privacy.asp" appendQueryString="false" logRewrittenUrl="true" />
</rule>
注意:不要忘记删除位置路径和旧的 URL 重写规则。
问候,贾尔帕
推荐阅读
- c# - JSON (JObject) 到 C# 对象:无法打印 Pusher 接收到的数据
- c# - 在 asp.net MVC 5(非核心)中使用 IDataProtectionProvider
- arrays - 尝试使用索引获取数组的上一项和下一项
- c++ - SIM 808 TCP 连接(Arduino 库)
- php - Laravel 在大集合中提高性能搜索的最佳方法
- chart.js - 使用 ChartJS 设置特定 X 轴标签的样式
- javascript - 在Javascript中将级别字符串转换为完全不同格式的数组
- ios - iOS Swift:UISegmentedControl Tint Color 与标题重叠
- python - Python:使用 BeautifulSoup4 在不同的内部访问新的
- r - 正则表达式和转义