简体   繁体   English

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

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

On web config I had written the following code as 在Web配置上,我编写了以下代码

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

Also Tried 也试过了

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

And when I am browsing the url as http://localhost:55390/blog/category/healthy-living-and-advice 当我以http:// localhost:55390 / blog / category / healthy-living-and-advice浏览url时

It is not changing to 它没有改变为

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

How can I rewrite the url ? 如何重写网址?

I want to change 我想改变

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

to

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

You need to capture the part of the url behind blog/category Also I'm not sure wether the url does contain a slash at the start. 您需要捕获URL的blog/category后面的部分。此外,我不确定URL开头是否确实包含斜杠。 So try this 所以试试这个

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

The question mark in the regex is just there because I'm not sure about the slash. 正则表达式中的问号就在那里,因为我不确定斜杠。 But the principle is you capture one part of your url and {R:1} is a reference to the contents of the first capture group. 但是原理是您捕获URL的一部分, {R:1}是对第一个捕获组的内容的引用。

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

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