【问题标题】:URL rewrite not working nee to change (/blog/category/) to (/)URL 重写不起作用需要将 (/blog/category/) 更改为 (/)
【发布时间】:2018-03-01 23:50:06
【问题描述】:

在网络配置上,我将以下代码编写为

 <system.webServer>
    <rewrite>
      <rules>
        <rule name="catalogsmain" stopProcessing="true">
          <match url="\/blog\/category\/" />
          <action type="Redirect" url="/" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>

也试过了

<system.webServer>
    <rewrite>
      <rules>
        <rule name="catalogsmain" stopProcessing="true" patternSyntax="ExactMatch">
          <match url="/blog/category/" />
          <action type="Redirect" url="/" />
        </rule>        
      </rules>
    </rewrite>
  </system.webServer>

当我浏览网址时 http://localhost:55390/blog/category/healthy-living-and-advice

不会变成

http://localhost:55390/healthy-living-and-advice

如何重写网址?

我想改变

http://mitesh.com/blog/category/healthy-living-and-advice

http://mitesh.com/healthy-living-and-advice

【问题讨论】:

    标签: c# asp.net url-rewriting nopcommerce


    【解决方案1】:

    需要截取blog/category后面的部分url 另外我不确定网址是否在开头包含斜杠。所以试试这个

    <system.webServer>
     <rewrite>
      <rules>
        <rule name="catalogsmain" stopProcessing="true">
          <match url="\/?blog\/category\/(.*)" />
          <action type="Redirect" url="/{R:1}" />
        </rule>
      </rules>
     </rewrite>
    </system.webServer>
    

    正则表达式中的问号就在那里,因为我不确定斜杠。但原则是你捕获你的url的一部分,{R:1}是对第一个捕获组内容的引用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-23
      • 2014-07-23
      • 2020-08-04
      • 1970-01-01
      • 2018-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多