【问题标题】:How can I create one rewrite to handle these multiple URLs using web.config?如何使用 web.config 创建一个重写来处理这些多个 URL?
【发布时间】:2013-10-09 17:40:13
【问题描述】:

这是我的重写示例(工作正常),旨在从 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>

【问题讨论】:

    标签: regex url-rewriting web-config


    【解决方案1】:

    我想通了。我希望我能解释得更好,但我习惯于 .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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-22
      • 2020-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-16
      相关资源
      最近更新 更多