2010-05-07 71 views
0

我需要创建的web.config规则将改写为文件的所有请求与扩展的.html为.asp和重定向所有的.asp请求为.htmlIIS URL重写重写所有的.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> 
+0

听起来像一个无限循环等待发生(ASP - > html - > asp ...) – Oded 2010-05-07 18:42:51

回答

0

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

您可以通过web.config设置重新编写您的网页。 如果您使用共享主机,我不会推荐使用ISAPI。

让我知道它是否适合你。

问候,安瓦尔

+0

我有我自己的服务器,所以这只是购买ISAPI_Rewrite的许可证并安装它或使用免费的URL与IIS 7重写的问题。 它们都是相当复杂的学习。正则表达式语法等。 – donxythe 2010-05-09 04:17:34

3

试试这个,ü应该知道$标签是重定向结束/重写条件和查询字符串将不被接受

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