[Dancer-users] Exploring Best Practices for Route Definition

Brian E. Lozier brian at massassi.com
Wed May 4 21:50:14 CEST 2011


On Wed, May 4, 2011 at 12:42 PM, J. Bobby Lopez <jbl at jbldata.com> wrote:
> Hello Dancers,
>
> I recently asked a question on #dancer regarding how to deal with trailing
> slashes on routes.  There was a brief discussion which resulted, and I've
> copied the the discussion below in order to get some more input on the
> matter.
> (with permission from gnusosa) please see the discussion below:
>
> ----------irc.perl.org------#dancer------------------------
> 14:54 < jbl> curious how others treat the difference between 'route' and
> 'route/' in dancer. I'm often using
> '/some/route', but then if a user tries to access the app with
> http://site.com/some/route/' (with the trailing
> slash) it gives a 404 by default. What's the usual cure for this problem?
> 14:55 < gnusosa> jbl: Good Question.
> 14:59 < gnusosa> jbl: This is going to happen since the slash "/" is the one
> that difference the route from the route/
> 15:02 < jbl> right
> 15:03 < jbl> I'm just wondering if I should add a wildcard or redirect to
> catch trailing slashes, or if there is a setting
> somewhere that checks if there are no other characters after the slash, to
> just treat it as base route
> 15:03 < jbl> not sure I'm being clear on that :\
> 15:04 < jbl> I think I saw the use of regexs for routes somewhere, that
> might be a good option
> 15:06 < jbl> to do something like: get '/myroute[/]*$'
> 15:07 < jbl> or maybe even just strip the trailing slashes using a 'before'
> statement
> 15:07 < gnusosa> jbl: Probably.
> 15:07 < jbl> curse of tmtowtdi
> 15:08 < gnusosa> jbl: But all of these seems like too much hassle.
> 15:08 < gnusosa> jbl: What is the problem with sending some people to 404 :P
> 15:10 < jbl> I guess that if the URL doesn't have an extension "/route.cgi"
> then some people (maybe just me) may feel that
>   URL is incomplete/incorrect/odd somehow. I guess they could go to a 404 if
> they type in the URL manually
> 15:11 < jbl> no real harm in that as long as the real URL works
> 15:11 < jbl> just feels off
> 15:11 < gnusosa> jbl: umm I understand now.
> 15:12 < jbl> and I remember at some point (back in the day) it was good
> practice to end URLs with a slash, if it wasn't
> going to a 'file'
> 15:16 < gnusosa> jbl: You should email the mailing list
> dancer-users at perldancer.org with this issue. Best practices in the
> routes are a big deal.
> ------------------------------------

I think ultimately you do not want two different URLs pointing to the
same content.  There are tons of articles on google webmaster blog
about this.  It's considered duplicate content when you have two urls
that return the same thing.  While it's not (alone) necessarily bad,
it's better to have a single URL for each unique piece of content.  I
think you should pick the one you like and make sure you always link
to the correct URL.  If people are typing in URLs and getting it
wrong, serve up a 404 page (with a real 404 return code) and link them
to the right URL.  Or 301 redirect to the right url if you can
determine it.


More information about the Dancer-users mailing list