Routing / URL question


I’m working on a project where I have an image map of the United States and small clickable dots/circles that represent each city. When the user clicks a city on the map I take them to a search results page.

The URLs currently look like this:

I’d like each of those URLs and all the other cities of course to be routed to one handler that passes in the city name

How can this be done?

I know I could do this with my URLS, but I’d like to have the URLs look like the above if possible, but still yield the same affect.

**<a** href="#event.buildLink(linkTo='',queryString='city=miami')#">**Miami****</a>**
**<a** href="#event.buildLink(linkTo='',queryString='city=houston')#">**Miami****</a>**

Thanks and any guidance appreciated. Maybe I should be doing it a completely different way so I’m open to any thoughts.


Enable web server rewrites to get rid of the index.cfm. Then configure a route for each state in /config/routes.cfm.

The routes will probably look something like this:

addRoute(pattern="/Houston", handler=“myHandler”, action=“index” city=“houston”);

If you have a lot, you could create them dynamically in a loop by pulling the data from a table.

You could also try a single general route like so:

addRoute(pattern="/:city", handler=“myHandler”, action=“index”);

but I’m pretty certain that would override your normal routes and cause general quirkiness. This could be GREATLY simplified If you were willing to settle for the following URLS:

Then a single route like so would work:

addRoute(pattern="/go/:city", handler=“myHandler”, action=“index”);

The word “go” is negotiable, but the point is, it gives you an anchor for your route to search for which differentiates it from any regular handler.

Everything you need to know is here in the docs:

A last ditch option would be to simply set up an onInvalidEvent handler which checked the current URL to see if a known city was in it and then ran the appropriate event.



ColdBox Platform Evangelist
Ortus Solutions, Corp

ColdBox Platform:

Thanks for the reply. I will try out some of these options. I didn’t even think about pulling them via query and looping over them. Since I have one url for each city there will definitely be a lot. The other options look interesting too so thanks for providing some guidance.

You can also create a constraint on the city where it has to match a regex. That way if it does not match the regex of cities then it continues.


Luis Majano
Ortus Solutions, Corp
Toll Free/Fax: 1-888-557-8057
Direct: 909-248-3408
Twitter: @lmajano, @ortussolutions