More about URL rewrites from yesterday... In othe...
# cfml-general
b
More about URL rewrites from yesterday... In other words, friendly URLs such as mydomain.com/my-slug-here CFML engines such as ACF, Lucee, and BoxLang do not offer URL rewrites out of the box. Nor do any popular CF frameworks such as FW/1, ColdBox, or CFWheels... As rewrites are optional. So if you want friendly URLs, you need to use URL rewrite patterns in your web server. There is no other way. That is, without some kind of hack. For me, the first step to writing modern CFML code is to avoid exposing index.cfm, or anything ending in .cfm for that matter. With some simple rewrite magic, you really don't have to. From there you can build any modern web-facing app, website, or API using CFML. Hope that helps someone.
r
IMO - it makes more sense for URL rewrite to be at the web server level since that is in front of all CF servers and doing the rewrite there allows for the web server to do what it does best while documenting how the friendly URL maps to the CF code.
👍 1
b
My solution (many years ago) was to get Apache to push 404 errors to index.cfm, along with the URL parameters. A few lines of code in application.cfm (yes, .cfm!) was enough to get the information needed to find the right page. It got trickier with URLs with multiple (unnamed) parameters but overall it worked a treat. One of my motivations, which holds true today, was to keep the logic in one place (cfml) rather than having some in Apache, some in cfml and some elsewhere like DB stored procedures.
d
Doesn't ColdBox have a whole Routing DSL? You do have to set things up, but the framework is there I think (not having actually built a ColdBox app).
m
For those using commandbox, i'd recommend reading this https://commandbox.ortusbooks.com/embedded-server/configuring-your-server/url-rewrites , fwiw, with fw/1, coldbox, and i'd suspect also cfwheels, the default rewrite rule from starting your server with --rewritesEnable will work with the built in framework routing out of the box.
b
Hey Guys, thanks for the comments. Routing is enabled by default on ColdBox, which gives you this... http://localhost/index.cfm/home/about But if you want to hide the index.cfm, they provide a list of optional rewrite rules on this page... https://coldbox.ortusbooks.com/the-basics/routing/requirements/rewrite-rules The same concept is true for all other frameworks... including Adam Tuttle's Taffy. I brought this up because I know some folks get confused by it. It is an extra step, but it's easy. Whether using a framework or not. Hope that helps
e
If you want to make life on yourself "fun," you could redefine in your app engine what the default index page. In both Lucee and AFC, you can tell the CF engine which files to look for CF code in. That solves your problem, nobody should know what you are using as you are embarrassed or something of the cfm. The second, rewrite engines, Apache Tomcat, Apache HTTPD, Nginx, among others, all support rewrites. As for nice-looking seo slugs, do what WordPress does: write your application so your "index" page, based upon request type, throws out a parameterized string that gets rewritten. That is the common standard for this. Now if you want to scale at some stupidly nearly absurd application base, you can save a whole 82 bits and < a millisecond of read time if you hard-link all your slugs as directories and place your index file in those.