我有以下網址:IIS重寫URL與extesion清潔URL
https://blog.test.com/search.aspx
和:
https://blog.test.com/post/2017/01/BlogPostNumberOne.aspx
想我要做: 重寫包含單詞post
的URL並將aspx
最後添加爲一個沒有擴展名的乾淨URL。因此,例如:
https://blog.test.com/search.aspx
- >NO模式匹配,什麼也不做
https://blog.test.com/post/2017/01/BlogPostNumberOne.aspx
- >MATCH,重寫到
https://blog.test.com/post/2017/01/BlogPostNumberOne
我試過以下的正則表達式:^(?=.*/post/)(?=.*aspx$)
和我的web.config看起來像這樣:
<rule name="Redirect to clean URL" stopProcessing="true">
<match url="^(?=.*/post/)(?=.*aspx$)" ignoreCase="true"/>
<action type="Redirect" url="{R:1}"/>
</rule>
它不是在所有的工作,有時它返回一個500。你有什麼想法如何正確rewirte我傳入的請求?
THX :)
它不起作用,因爲您只使用零寬度斷言而沒有在「{R:1}」替換中引用的捕獲組。將正則表達式改爲'url =「^(。*/post /.*)\。aspx $」' –