【问题标题】:URL rewrite rule to replace old url .aspx to a new mvc routeURL 重写规则将旧 url .aspx 替换为新的 mvc 路由
【发布时间】:2012-12-08 06:33:13
【问题描述】:

我有一个要翻译成 MVC 的 webforms 网站,但我希望某些 url 已被编入索引以在 mvc 网站中找到他们的新 url,而我正在努力解决以下问题:

http://www.domain.com/content/reviews/I_once_answered_a_question_in_SO_page512.aspx

我想把它翻译成这样的格式:

http://www.domain.com/view/512/I_once_answered_a_question_in_SO

目前为止最好的:

<rule name="content pages" stopProcessing="true">
     <match url="^.*(?:content/(.*)_page([0-9]+)\.aspx)$" />
     <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
         <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
     </conditions>
     <action type="Redirect" url="/view/{R:2}/{R:1}"/>
</rule>

我认为它非常接近,但我不明白为什么它不匹配。

【问题讨论】:

    标签: iis-7 url-rewriting iis-7.5 rewrite url-rewrite-module


    【解决方案1】:

    很简单,你很接近,确实需要在内容文件夹和文档页面之间添加一个额外的条件:

        <rule name="content pages" stopProcessing="true">
          <match url="^.*(?:content/(.*)/(.*)_page([0-9]+)\.aspx)$" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
            <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
          </conditions>
          <action type="Redirect" url="/view/{R:3}/{R:1}/{R:2}"/>
        </rule>
    

    【讨论】:

    • 哦,是的,它有效,为什么我没有尝试呢?我可能错过了,太简单了!谢谢本
    猜你喜欢
    • 1970-01-01
    • 2013-03-06
    • 2018-09-09
    • 2012-04-05
    • 2011-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-22
    相关资源
    最近更新 更多