如何使用web.config创建一个重写来处理这些多个URL?

时间:2013-10-09 17:40:14

标签: regex url-rewriting web-config

以下是我的重写(工作正常)的示例,旨在从URL中删除index.cfm。

然而,我不想像下面那样进行多次重写,而是希望只有一个可以处理所有重写。

我当时认为必须有一个匹配此模式的正则表达式,以便我只能有一个规则。

<rule name="Remove index.cfm from About Us" stopProcessing="true">
  <match url="index.cfm$" />
    <conditions>  
      <add input="{QUERY_STRING}" pattern="page=8467" />  
    </conditions>  
    <action type="Redirect" url="http://www.mydomain.com?page=8467" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="Remove index.cfm from Biography Page" stopProcessing="true">
  <match url="index.cfm$" />
    <conditions>  
      <add input="{QUERY_STRING}" pattern="page=8469" />  
    </conditions>  
    <action type="Redirect" url="http://www.mydomain.com?page=8469" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="Remove index.cfm from Video Page" stopProcessing="true">
  <match url="index.cfm$" />
    <conditions>  
      <add input="{QUERY_STRING}" pattern="page=8473" />  
    </conditions>  
    <action type="Redirect" url="http://www.mydomain.com?page=8473" redirectType="Permanent" appendQueryString="false" />
</rule>

1 个答案:

答案 0 :(得分:0)

我明白了。我希望我能更好地解释,但我习惯了.htaccess而不是web.config。

<rule name="Remove index.cfm from URLs" stopProcessing="true">
  <match url="index.cfm$" />
    <conditions>  
      <add input="{QUERY_STRING}" pattern="page=([0-9]+)" />  
    </conditions>  
  <action type="Redirect" url="http://www.mydomain.com/?page={C:1}" redirectType="Permanent" appendQueryString="false" />
</rule>