在Web.config中加入下列的rewrite URL設定即可
[rewrite]
[rules]
[rule name="Hide .html ext"]
[match ignorecase="true" url="^(.*)"]
[conditions]
[add input="{REQUEST_FILENAME}" matchtype="IsFile" negate="true"]
[add input="{REQUEST_FILENAME}" matchtype="IsDirectory" negate="true"]
[add input="{REQUEST_FILENAME}.html" matchtype="IsFile"]
[/add][/add][/add][/conditions]
[action type="Rewrite" url="{R:0}.html"]
[/action][/match][/rule]
[rule name="Redirecting .html ext" stopprocessing="true"]
[match url="^(.*).html"]
[conditions logicalgrouping="MatchAny"]
[add input="{URL}" pattern="(.*).html"]
[/add][/conditions]
[action type="Redirect" url="{R:1}"]
[/action][/match][/rule]
[/rules]
[/rewrite]
參考資料
https://www.youtube.com/watch?v=0hlTdi6qijQ
https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference
留言