eCommerce URLs

I asked this on another list but seeing how I will be using coldbox I figured I would ask it here as well…





It would be nice if ColdBox allowed us to define these routes at the hander level.

No your not following… Say I ran a clothing store

How do I map those and where do i map them?

You would need to check all your categories against the beginning URL, and then go down to products if it doesn’t match.

I don’t see any other reasonable way to do it.

Depending on how many categories you have, you could hard code them into a mod_rewrite rules.


Looking at the example below, you can cheat a little. Categories don’t have ‘-’ in them :slight_smile:


You are brilliant! I do have 2 main top level categories.

I have 2 top level categories and everything else under these 2 would be sub categories

top level category

sub categories

single product (this works because its not men||women)




Now the only issue I seem to have is this. If they visit /products/men or /women than its directed to listByCategory action without a category name. So to take care of this I added a custom variable to the route called category. If category does not exist it will default to men or women, if it does it will just overwrite it!


FRACKING AWESOME! You rock coldbox!

Does this look good peeps?

Sounds good to me :slight_smile:


one quick correction for those following along at home… the product can’t be optional, so the route would look like this


I helped a client migrate to ColdBox who had a similar issue. There was not simple convention like “if it has a dash, its X” logic. Their previous system had a string in a database called URLNAME that needed to be referenced. For them, I grabbed all of the records, cached the query and performed a query of queries.

You could keep your handlers/routes organized as Andrew suggested and use the routes.cfm PathInfoProvider() method to rewrite the URL before the SES interceptor does it’s thing. You might prepend “products/” to the CGI.PATH_INFO returned by the PathInfoProvider() method to allow ColdBox to instantiate the “Products” handler.

For example, on my favorite video site, we need to support quite a few routes that all end up in the same handler:

  • /watch/:show/:episode/
  • /de/watch/:show/:episode/
  • /m/de/watch/:show/episode/
  • And so on…
    I use the PathInfoProvider() method within the routes.cfm file to set some values into my Event object to communicate the language and if the request is mobile, clean up the route and return “/watch/{show}/{episode}”. While this example is not solving your problem I hope it helps demonstrate the power of adding a PathInfoProvider() method to your routes.cfm file. It basically allows you to rewrite the URL within ColdFusion so you can apply application logic and returns a string that is evaluated by the SES Interceptor. Without such a function the SES interceptor simply uses the CGI.PATH_INFO to evaluate your route.

Here is the method signature to help save a trip to the docs.

string function PathInfoProvider(Event)
var rc = Event.getCollection();
var prc = Event.getCollection(private=true);

var path = CGI.PATH_INFO;
// Do your thing here
return modifiedPath;

Aaron Greenlee

Good stuff Aaron, thanks!