繁体   English   中英

IIS URL重写将所有.asp重写为.html

[英]IIS url rewrite rewriting all .asp to .html

我需要为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

  1. 该规则的语法是什么
  2. 这太笼统了吗? 如果我出于任何原因需要拥有物理文件(例如file_abc.html),如何将其从重定向规则中排除?
  3. 我想我应该只使用ISAPI_Rewrite http://www.isapirewrite.com/ ,似乎有大量资源可以用htaccess进行重写,而使用IIS 7 URL重写的在线帮助非常少。 任何想法和/或建议

提前致谢

到目前为止,这是我对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>

尝试此操作,您应该知道$标签是重定向/重写条件的结尾,并且不接受查询字符串

<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>

看一下这篇文章: http : //weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

您可以通过web.config设置重新编写网页。 如果您使用共享托管,我不建议您使用ISAPI。

请让我知道这对你有没有用。

问候,安瓦尔

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM