[英]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
至
您需要捕获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.