使用 web.config 将旧页面重定向到新页面

时间:2021-02-09 16:30:52

标签: iis url-rewriting

我需要将旧页面的 url 重写到新页面,例如: 旧:https://www.mysite.it/scheda.asp?num=123456 新:https://www.mysite.it/scheda/?num=123456

我在 web.config 中添加了以下几行但不起作用,当我转到 https://www.mysite.it/scheda.asp?num=123456 时注意到发生了,站点转到页面而无需重写:

  <rule name="scheda-rew" stopProcessing="true">
      <match url="scheda.asp(.*)" />
      <action type="Rewrite" url="scheda/{R:1}" logRewrittenUrl="true" />
  </rule>

我试试这个:

<rule name="scheda-rew2" stopProcessing="true">
    <match url="^scheda\.asp" ignoreCase="true" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{QUERY_STRING}" pattern="isbn=([0-9]+)" />
    </conditions>
    <action type="Redirect" url="scheda/{C:1}" appendQueryString="false" />
</rule>

什么都没有,似乎我所做的所有更改都没有效果

1 个答案:

答案 0 :(得分:0)

您可以尝试以下规则,如果您有任何问题,请告诉我:

<rule name="RewriteUserFriendlyURL2" stopProcessing="true">
   <match url="^scheda.asp\?([^/]+)/?$" />
       <conditions>
            <add input="{​​​​​​​REQUEST_FILENAME}​​​​​​​" matchType="IsFile" negate="true" />
            <add input="{​​​​​​​REQUEST_FILENAME}​​​​​​​" matchType="IsDirectory" negate="true" />
            <add input="{​​​​​​​REQUEST_URI}​​​​​​​" pattern="^scheda/$" negate="true" />
       </conditions>
   <action type="Redirect" url="scheda/?num=123456" appendQueryString="false" />
</rule>
相关问题