[英]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.