【问题标题】:IIS Redirect Permanent to part of old URLIIS 永久重定向到旧 URL 的一部分
【发布时间】:2021-02-10 19:15:32
【问题描述】:

我正在尝试使用 IIS 重写永久重定向此内容

www.domain.com/category/sub-category/product-slugwww.domain.com/category/product-slug

www.domain.com/product-slug

旧网址来自 magento2,而新网站在 nopCommerce 上

基本上,我希望将每个 URL 重定向到 domain.com/product-slug。我怎样才能做到这一点?

我们将不胜感激。

【问题讨论】:

    标签: asp.net-core iis url-rewriting web-config asp.net-mvc-routing


    【解决方案1】:

    您可以尝试以下规则:

    <rule name="test1" stopProcessing="true">
     <match url="(.*)" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="www.test.com" />
        <add input="{REQUEST_URI}" pattern="^/([^/]+)/([^/]+)/([^/]+)$" />
      </conditions>
      <action type="Redirect" url="http://www.test.com/{C:1}/{C:3}" />
    </rule>
    

    <rule name="test2" stopProcessing="true">  
        <match url="(.*)" />
            <conditions>
              <add input="{HTTP_HOST}" pattern="www.test.com" />
              <add input="{REQUEST_URI}" pattern="^/([^/]+)/([^/]+)$" />
             </conditions>
        <action type="Redirect" url="http://www.test.com/{C:1}/{C:2}" />
     </rule>
    

    正文不能包含“http://www.domain.com”,所以我使用www.test.com

    【讨论】:

    • category 和 product-slug 只是占位符。我如何为每个类别的价值做些什么。例如我想要 www.test.com/computers/desktops/awesome-desktop 到 www.test.com/awesome-desktop 等等。不过感谢您的帮助。
    • @ghulam_ali 我修改了答案,请查看更新后的帖子。
    猜你喜欢
    • 1970-01-01
    • 2018-02-19
    • 2012-08-05
    • 1970-01-01
    • 2012-04-18
    • 2012-06-16
    • 2017-04-19
    • 2011-08-07
    • 2010-11-24
    相关资源
    最近更新 更多