Routing / URL question

Hi,

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:

http://www.abc.com/houston
http://www.abc.com/dallas
http://www.abc.com/chicago
http://www.abc.com/losangeles
http://www.abc.com/miami

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='general.city',queryString='city=miami')#">**Miami****</a>**
**<a** href="#event.buildLink(linkTo='general.city',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.

Thanks…

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:

http://www.abc.com/go/houston
http://www.abc.com/go/dallas
http://www.abc.com/go/chicago
http://www.abc.com/go/losangeles
http://www.abc.com/go/miami

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:

http://wiki.coldbox.org/wiki/URLMappings.cfm

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.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

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.

Constraints={city="(miami|houston|ny)"

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