Enabling trailing slash

Apr 29, 2012 at 8:58 PM

I had the issue that my customer wanted trailing slash on all urls in the project. I of course use LowercaseRoutesMVC.

Because LowercaseRoutesMVC gets responsible for creating urls I was forced to edit the source to add the trailing slash. 

If I'm right that there isn't an elegant way to add the slash, without editing the source of LowercaseRoutesMVC, shouldn't it be implemented as a feature? I've created a pull request with my implementation.

Thanks :-)

- Jonas

Coordinator
Apr 29, 2012 at 9:17 PM

I understand your issue; however, this is really out of scope for this project.

In this case, I would probably go with using an IIS rewrite rule to add the trailing slash. Something like this (this is just from memory)

<rule name="Add Trailing Slash" stopProcessing="true">
  <match url=".*" />
  <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_URI}" pattern=".*/$" negate="true" />
  </conditions>
  <action type="Redirect" url="{R:0}/" />
</rule>

Apr 29, 2012 at 9:21 PM

That would be causing a HTTP redirect to every single link in your site. That's simply not a solution, it kills SEO.

I agree it's kinda out of scope, but at the same time, it's becoming best practice to add this trailing slash. By avoiding to implement the feature in LowercaseRoutesMVC, people who care about SEO is forced to use something else. Do you follow me?

Coordinator
Apr 30, 2012 at 4:32 PM

If you use redirectType="Permanent" it would actually help your SEO. Remember, even if your application generates the trailing slash, you cannot assure that people will always use it when they link to you. This way, IIS will issue a 301 whenever someone hits your site without the slash. That way, search engines will ONLY index the trailing slash URL, and will never index the non-slash version.

If you really need to force the application to generate the trailing slash, then what you've done (modifying the library for your own purposes) is totally fine. That's what forks are for.

All this library is intended to do is to take the exact URL that would have been generated by default and lower-case it, nothing more. As I mentioned, modifying the URL in any other way would not be in that scope.