在 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
它不会更改为
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}
是对第一个捕获组内容的引用。