Blog

Tip of the Week: ColdBox Routes

Brad Wood November 28, 2012

Spread the word

Brad Wood

November 28, 2012

Spread the word


Share your thoughts

 

Hopefully you are already familiar with the format of a default ColdBox URL when using the SES interceptor.  
 
mysite.com/index.cfm/myHandlerName/myActionName
 
Of course, a simple rewrite rule can simplify that even further to:
 
mysite.com/myHandlerName/myActionName
 
What you may not realize is that URL pattern is called a "route" and not only can be changed, but you can add as many customized routes as your application desires.  The magic happens in your /config/routes.cfm file where all the routes are declared in the order they should be processed.  You'll find the default route in that file:
 
addRoute(pattern=":handler/:action?");
 
The syntax for adding a new custom route looks like this:
 
addRoute(pattern="/URLStringToMatch", handler="handlerName", action="actionName");
 
That means, you could set up a route like so:
 
addRoute(pattern="/blog", handler="entryHandler", action="listEntries");
 
Now, the following two URLs would point to the exact same thing (with the second option being obviously preferable):
 
mysite.com/entryHandler/listEntries
mysite.com/blog
 
You can even clean up URLs that have variables.  Consider the following page on your site:
 
mysite.com/services/products/productDetail/productID/1234
 
Just add a new route that looks like this:
 
addRoute(pattern="/product/:productID", handler="services.products", action="productDetail");
 
And now the following URL will give you the same page:
 
mysite.com/product/1234
 
As you can see, routes are a very powerful way to keep those URLs looking sharp, but we're barely scratching the surface of what you can do.  Don't get intimidated though-- read through the docs dive in!
 
 

Add Your Comment

Recent Entries

12 Days of BoxLang - Day 6: BoxLang AI

12 Days of BoxLang - Day 6: BoxLang AI

BoxLang AI gives you a unified, consistent way to work with Large Language Models—across multiple providers—using a single functional and fluent API. Build AI-powered features directly into your BoxLang apps without juggling different SDKs, formats, or request models.

You can also extend capabilities with bx-aiplus, part of our BoxLang + / ++ subscriptions, which adds more providers, advanced features, and enhancements.

Maria Jose Herrera
Maria Jose Herrera
December 16, 2025
12 Days of BoxLang - Day 5: Cloud Servers

12 Days of BoxLang - Day 5: Cloud Servers

One of the most powerful parts of the BoxLang ecosystem is how easily it can run anywhere — locally, on-premise, containers, and especially in the cloud. Today we’re highlighting BoxLang Cloud Servers, our official, optimized virtual machines available across major cloud platforms. ☁️⚡

If you’re building BoxLang, ColdBox, or CommandBox applications, these cloud-ready images give you a fast, secure, and scalable way to deploy your apps with minimal configuration and maximum performance.

Maria Jose Herrera
Maria Jose Herrera
December 15, 2025
12 Days of BoxLang - Day 4: TestBox

12 Days of BoxLang - Day 4: TestBox

Today we’re celebrating one of the most exciting new additions to the BoxLang ecosystem:

the TestBox BoxLang CLI Runner a fast, native way to run your TestBox tests directly through the BoxLang Runtime. ⚡

No server required. No CommandBox needed. Just pure, ultra-fast BoxLang-powered testing from the command lineon Windows, Mac, and Linux.

If you’re building modern applications with BoxLang — web apps, CLIs, serverless functions, Android apps, or OS-level utilities — this new feature gives you a unified, flexible testing workflow you can run anywhere.

Victor Campos
Victor Campos
December 13, 2025