Remove Traiing Foward Slash using UrlRewritingNet

2019-08-02 21:56发布

i'm doing some work on a legacy asp.net and umbraco site. It's using UrlRewritingNet to set up rules for url manipulation.

I'd like to create a rule in the UrlRewritingNet file to remove the trailing slash from the url.

eg. http://www.test.com/index.aspx/ to http://www.test.com/index.aspx

Can you please help.

3条回答
再贱就再见
2楼-- · 2019-08-02 22:20

You can use the TrimEnd() method.

return inputString.TrimEnd('/'); // .NET 2 or newer

or

return inputString.TrimEnd(new char[] { '/' }); // legacy
查看更多
家丑人穷心不美
3楼-- · 2019-08-02 22:25

In the later versions of IIS in the url rewrite section you can set up these SEO rules without having to change code. Just 'add rules' in the 'url rewrite' section of the website:

enter image description here

查看更多
唯我独甜
4楼-- · 2019-08-02 22:38
<add name="noendslash" 
            virtualUrl="^(.*)/$" 
            rewriteUrlParameter="IncludeQueryStringForRewrite" 
            redirect="Application"
            destinationUrl="~$1"
            ignoreCase="true" />
查看更多
登录 后发表回答