don*_*the 0 asp.net iis iis-7 web-config url-rewriting
我需要为 web.config 创建规则,它将所有扩展名为 .html 的文件请求重写为 .asp 并将所有 .asp 请求重定向到 .html
示例:
file_xyz.asp 重写为 file_xyz.html
directory1/file_xyz.asp 重写为 directory1/file_xyz.html
和
file_xyz.html 重定向到 file_xyz.asp
directory1/file_xyz.html 重定向到 directory1/file_xyz.asp
提前致谢
到目前为止,这是我对 web.config 的语法
<rule name="RewriteHTMLtoASP" stopProcessing="true">
<match url="^([^/]+)\.html$" />
<conditions logicalGrouping="MatchAll" />
<action type="Rewrite" url="{R:1}.asp" />
</rule>
<rule name="RedirectASPtoHTML" stopProcessing="true">
<match url="^([^/]+)\.asp$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_METHOD}" pattern="^GET$" />
</conditions>
<action type="Redirect" url="{R:1}.html" appendQueryString="false" />
</rule>
Run Code Online (Sandbox Code Playgroud)
试试这个,你应该知道 $ 标签是重定向/重写条件的结束,并且不会接受查询字符串
<rule name="RewriteHTMLtoASP" stopProcessing="true">
<match url="(.*).html(.*)" />
<conditions logicalGrouping="MatchAll" />
<action type="Rewrite" url="{R:1}.asp{R:2}" />
</rule>
<rule name="RedirectASPtoHTML" stopProcessing="true">
<match url="(.*).asp(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_METHOD}" pattern="^GET$" />
</conditions>
<action type="Redirect" url="{R:1}.html{R:2}" appendQueryString="true" />
</rule>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10592 次 |
| 最近记录: |