簡體   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