繁体   English   中英

URL重写无法正常工作,无法将(/ blog / category /)更改为(/)

[英]URL rewrite not working nee to change (/blog/category/) to (/)

在Web配置上,我编写了以下代码

 <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浏览url时

它没有改变为

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

如何重写网址?

我想改变

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

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

您需要捕获URL的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}是对第一个捕获组的内容的引用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM