Core Routing engine not properly handling trailing / for URLs


Our clients are complaining. There's times where URLs, for whatever reason, have trailing '/'. They should not 404.

Orchard sites:

http://nwazet.com/us - works
http://nwazet.com/us/ - 404

http://orchardproject.net/contribution - works
http://orchardproject.net/contribution/ - 404

Non-Orchard sites:

http://about.me/sebastienros - works
http://about.me/sebastienros/ - works

http://twitter.com/bleroy - works
http://twitter.com/bleroy/ - works

I don't think it's realistic to expect rewrite rules to cover every URL or URL pattern to handle trailing slash. The default behavior should be to simply ignore the trailing slash and load the page as if it wasn't added. Please fix.
Closed Apr 23, 2013 at 6:19 AM by BertrandLeRoy
See comments


pszmyd wrote Apr 23, 2013 at 12:05 AM

A workaround would be to add a rewrite rule to rewrite or 301 redirect URLs with trailing slash to the one without it.

morrisonbrett wrote Apr 23, 2013 at 12:06 AM

@Pszmyd - that's not an acceptable workaround for us.

morrisonbrett wrote Apr 23, 2013 at 12:38 AM

Well we could add a rewrite rule but I wonder if it should be in Core. Thoughts?

<rule name="Remove trailing slash" stopProcessing="true">
<match url="(.*)/$" />
<action type="Redirect" redirectType="Permanent" url="{R:1}" />

BertrandLeRoy wrote Apr 23, 2013 at 1:09 AM

Why is it not an acceptable workaround?

BertrandLeRoy wrote Apr 23, 2013 at 1:10 AM

Including that rewrite rule in core doesn't seem possible, as rewrite is an optional IIS module. Furthermore, which of the two conventions do we make canonical? With or without the slash?

BertrandLeRoy wrote Apr 23, 2013 at 6:19 AM

Additional reasons this shouldn't be in core:
This is the standard MVC behavior. You may have different resources behind both URLs. Search engines will actually treat them differently. Here is an excellent link provided by Piotr that explains it well: http://googlewebmastercentral.blogspot.com/2010/04/to-slash-or-not-to-slash.html