SES URLs with extra stuff at the end still parsing after valid Route has been found

I’ve come across a problem and am looking for a solution.

Given a URL: http://www.mydomain.com/route/action/foo/bar, the default action is that ColdBox will resolve to http://www.mydomain.com/route/action but the URL will still be at http://www.mydomain.com/route/action/foo/bar. I’m trying to make it so that if the user goes to http://www.mydomain.com/route/action/foo/bar, they will be displayed a 404 error page, INSTEAD of the resolved view.

I’ve looked at a couple settings within ColdBox, namely getLooseMatching and getUniqueURLs but don’t think I’m heading in the right direction.

Is this possible within ColdBox? For details, I’m currently on ColdBox 3.5 / 3.7, running on ColdFusion 10 on top of IIS and Windows 2012. Any help would be greatly appreciated.

-Chester

What you’re seeing is a feature. Any name/value pairs found after the matched rout are scoped in to the request collection.

https://coldbox.ortusbooks.com/content/full/routing/routing_by_convention.html

The docs are for 4+, but 3.5 had this too.

The setting you are looking for, to turn it off in your routes configuration, is “valuePairTranslation”: https://coldbox.ortusbooks.com/content/full/routing/adding_routes.html

-Jon

ColdBox SES has a parameter you can specify when declaring a route called valuePairTranslation=false that will tell SES to ignore any additional bits that it finds after the route, however that’s not really what you’re asking for.

After a quick review of the code and the docs I don’t think there’s actually a way to have SES ONLY match the route and throw an event not found if the routed URL isn’t an exact match. I don’t think anyone has ever asked for this before. This there a specific reason why you don’t want to allow extra bits at the end of the route?

If you really want to, you could make a check of your own to try and sniff out when the URL has extra stuff that wasn’t strictly part of the matched route. For the default convention route (:handler/:action) you’d need to compare event.getCurrentRoutedURL() with event.getCurrentEvent() and replace slashes with dots. In the case of a custom route with no placeholders, you’d need to compare event.getCurrentRoute() with event.getCurrentRoutedURL(). For the case of a custom route that has placeholders, I’m not sure there would be an easy way to do it.

Maybe if you have a good use case for this you can enter a ticket.

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Jon, turning off valuePairTranslation will prevent the extra bits from getting placed in the rc, but it won’t prevent the route from being matched. I actually gave it a quick test prior to sending my previous E-mail. I created this route:

addRoute(pattern=“foo”, handler=“main”, action=“index”, valuePairTranslation=true );

And hit this URL:

/index.cfm/foo/bar/baz

and ColdBox still matched the route. It didn’t place bar=baz in the rc, but it still matched the route. That’s because the regex actually being generated in the SES interceptor requires the match to be at the start of the string (unless you have loose matching enabled) but it never enforces anything in regards to the end of the string being matched.

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Whoops, I meant to type valuePairTranslation=false below, not =true! My observation still stands, I just typed the wrong route example in!

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

All,

Thanks for your input. As for use case, we’re of the idea that, in order to have consistent URLs for SEO, those that don’t conform to a view: https://www.mydomain.com/route/action/foo/bar SHOULDN’T resolve to the desired page. What do others think of this reasoning? For anyone with SEO experience, would it be “better” to 404 on a URL like that or get the user to where they want to be, even if there are extra items on their URL?

Thanks for illuminating a way forward. I’ll check out which solution would work in this case.

-Chester

I’ve never seen an issue with SEO in regards to that. Google is smart enough to know it’s the same page and it’s not going to find links with extra stuff on the end unless you’re using that in your site. And in every case I’ve put variable into the SES route, it affects the contents of the page, so in that case I WANT it to be different.

site.com/order/view/ID/123
site.com/order/view/ID/456
site.com/order/view/ID/789

All three of those pages may run the same order.view event, but Google should index them separately since they have different information on them.

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

What we’ve been seeing, and I’m not even sure how it’s being done, are views from: site.com/order/view/ID/123/order/order/view or something like that. What we’re trying to prevent is the /order/order/view from viewing site.com/order/view/ID/123.