【问题标题】:URL Rewriting - removing the entire page nameURL 重写 - 删除整个页面名称
【发布时间】:2014-07-09 19:24:40
【问题描述】:

目前我的 web.config 中有一个重写规则,它删除了“.aspx”页面扩展名。

我想重写我的 URL 以删除整个页面名称“page1.aspx”,这样我的 URL 将显示为“www.mysite.com/folder/”而不是“www.mysite.com/folder/page1”

我目前使用的 web.config 中的重写代码如下:

<rewrite>
  <rules>
    <clear />
    <rule name="Redirect to clean URL" enabled="true" stopProcessing="true">
      <match url="^([._0-9a-z-/]+).aspx$" ignoreCase="true" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
      <action type="Redirect" url="{R:1}" />
    </rule>
    <rule name="RewriteASPX" enabled="true">
      <match url="(.*)" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      </conditions>
      <action type="Rewrite" url="{R:1}.aspx" />
    </rule>
  </rules>
</rewrite>

我需要在当前规则中添加或编辑什么以获得所需的结果?

谢谢!

【问题讨论】:

    标签: asp.net url-rewriting


    【解决方案1】:

    在 regex101.com 上快速测试一下,这行得通吗?

    <match url="^([._0-9a-z-/]+)/(.+).aspx$" ignoreCase="true" />
    

    <action type="Redirect" url="{R:0}/" />
    

    添加“/(.+)”可确保 aspx 之前的最后一个单词从第一个匹配项 (R:0) 中删除。 R:1 将包含该词:“page1”,而 R:0 将包含:“www.mysite.com/folder”。

    【讨论】:

      猜你喜欢
      • 2013-09-16
      • 2021-10-27
      • 2011-07-02
      • 2013-07-16
      • 1970-01-01
      • 1970-01-01
      • 2020-09-09
      • 2011-01-19
      • 2014-12-07
      相关资源
      最近更新 更多