1

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.

Kojof
  • 429
  • 7
  • 15
  • 23

3 Answers3

2
<add name="noendslash" 
            virtualUrl="^(.*)/$" 
            rewriteUrlParameter="IncludeQueryStringForRewrite" 
            redirect="Application"
            destinationUrl="~$1"
            ignoreCase="true" />
Joan Caron
  • 1,969
  • 18
  • 21
1

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

amelvin
  • 8,919
  • 4
  • 38
  • 59
  • I know about this, but it's a legacy application, so i am not able to implement this solution, only using the urlrewritingnet file. – Kojof Mar 25 '13 at 18:36
0

You can use the TrimEnd() method.

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

or

return inputString.TrimEnd(new char[] { '/' }); // legacy
Nolonar
  • 5,962
  • 3
  • 36
  • 55