简体   繁体   English

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

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

I need to create rules for web.config that will rewrite all requests for files with extension .html to .asp and redirect all .asp requests to .html 我需要为web.config创建规则,以将扩展名为.html的文件的所有请求重写为.asp并将所有.asp的请求重定向到.html

Example: 例:
file_xyz.asp rewrites to file_xyz.html file_xyz.asp重写为file_xyz.html
directory1/file_xyz.asp rewrites to directory1/file_xyz.html directory1 / file_xyz.asp重写为directory1 / file_xyz.html
and

file_xyz.html redirects to file_xyz.asp file_xyz.html重定向到file_xyz.asp
directory1/file_xyz.html redirects to directory1/file_xyz.asp directory1 / file_xyz.html重定向到directory1 / file_xyz.asp

  1. What is the syntax for the rule 该规则的语法是什么
  2. Is this too broad a rule? 这太笼统了吗? If I should need for what ever reason to have a physical file such as file_abc.html how do I exclude it from the redirect rule? 如果我出于任何原因需要拥有物理文件(例如file_abc.html),如何将其从重定向规则中排除?
  3. I am thinking I should just use ISAPI_Rewrite http://www.isapirewrite.com/ there seems to be a ton of resources out there for rewriting with htaccess and very little online help for using IIS 7 URL rewrite. 我想我应该只使用ISAPI_Rewrite http://www.isapirewrite.com/ ,似乎有大量资源可以用htaccess进行重写,而使用IIS 7 URL重写的在线帮助非常少。 Any thoughts and/or advice 任何想法和/或建议

Thanks in advance 提前致谢

So far this is the syntax I have for the web.config 到目前为止,这是我对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>

Try this, u should know $ tag is the end of redirect/rewrite condition and querystrings will not accepted 尝试此操作,您应该知道$标签是重定向/重写条件的结尾,并且不接受查询字符串

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

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

You can re-write your web pages via web.config settings. 您可以通过web.config设置重新编写网页。 If you use shared hosting I would not recommend to use ISAPI. 如果您使用共享托管,我不建议您使用ISAPI。

Let me know if it works for you. 请让我知道这对你有没有用。

Regards, Anvar 问候,安瓦尔

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

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