Removing old CFM files after moving to Coldbox

We are in the process of switching some of our legacy app to Coldbox a few pages at a time. One of the things we are doing now is taking the old files such as /example.cfm and breaking it up into views and components to match the Coldbox convention.

However as would be expected when we delete the file /example.cfm we get a 404 error from Tomcat. The reason for this is because of the way our Apache HTTPD and Tomcat is configured. We proxy any requests that contain .cfm, .cfml, .cfc in the extension from HTTPD to Tomcat, where as if the request doesn’t contain those file extensions it processes the .htaccess file in the root directory using the default Coldbox configuration.

I am curious if anyone knows how I would configure it so that it only proxies to Tomcat when a file or directory match is found that contains the above mentioned CFML extensions? We don’t really want to keep around all the old files that will just contain a redirect. Our goal would be to make a Coldbox route that does the redirect for us if someone should visit the old link. Thanks in advance for any help.

NOTE: I have looked at several answers on Stackoverflow that do what I am asking but for some reason I keep getting weird redirect errors and bad requests. I have tried many different combinations but still nothing works so I am hoping someone here has done something similar in the past.

My HTTP VirtualHost for development is setup like so:

<VirtualHost *:80>
    DocumentRoot "E:/ExampleDir"
    ServerName dev.example.com
    RequestHeader set https on
    DirectoryIndex default.cfm index.cfm index.htm index.html

    RewriteEngine on

    <IfModule proxy_module>
        ProxyPreserveHost On
        ProxyRequests Off
        
        ProxyPassMatch ^/ws/(.*)$ ws://192.168.56.101:8888/ws/$1
        ProxyPassMatch ^/(.+\.lucee)(/.*)?$ ajp://192.168.56.101:8009/$1$2
        ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ ajp://192.168.56.101:8009/$1$2
        ProxyPassMatch ^/(.+\.cfchart)(/.*)?$ ajp://192.168.56.101:8009/$1$2
        ProxyPassMatch ^/(.+\.cfml)(/.*)?$ ajp://192.168.56.101:8009/$1$2
    </IfModule>

    ErrorDocument 404 /errors/404.cfm
  </VirtualHost>

Here is the .htaccess rules inside of the root directory

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/(.*(CFIDE|cfide|CFFormGateway|jrunscripts|railo-context|lucee|mapping-tag|fckeditor)).*$
RewriteRule ^(.*)$ - [NC,L]

RewriteCond %{REQUEST_URI} \.(bmp|gif|jpe?g|png|css|js|txt|xls|ico|swf)$
RewriteRule ^(.*)$ - [NC,L]

RewriteRule ^$ default.cfm [QSA,NS]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.cfm%{REQUEST_URI} [QSA,L,NS]

Can you show the actual URL you’re hitting in the browser before and after ColdBox? There’s a lot of missing information here. For instance, are you using SES URLs? Are you using rewrites? Are you trying to make the old URLs still proxy through to the ColdBox handlers?

A URL like so should still hit CF because of the .cfm

site.com/index.cfm/main/index

And with a URL rewrite rule, you can do this and the index.cfm gets added back on on the server

site.com/main/index

Also, check out this article which shows several different methods of integration ColdBox into a legacy app:

1 Like

So for example a url that looks like this https://example.com/products/productView.cfm?productID=1234 would be assigned a coldbox route of https://example.com/products/1234. Yes we are trying to use SES urls when we convert it to using Coldbox. Yes we are using the default .htaccess rewrites provided in the coldbox documentaion. Yes we are trying to get the old urls to proxy through a Coldbox handler that would essentially just pull out the parameters from the URL and call setNextEvent so that it goes through the new handler.

I will check out the legacy app demo to see if there is some similaritys to what we are trying to accomplish now.

Just to be clear, while this route below would definitley be a common way to build out the route in a ColdBox app, this is not going to be any built in route unless you’ve created it yourself:

https://example.com/products/1234

You haven’t shared the name of the handler and action you’re using, but if you created a “products” handler and have a “productView” action (method) then the built-in route Coldbox creates for you would be:

https://example.com/products/productView/productID/1234

To create the customized route you showed is easy though, you’d add a line like this to your routes.cfm (untested…)

addRoute( pattern="products/view/:productID", handler="products" action="productView" );

Then hitting your URL above, it would run the products.productView event and rc.productID would be available in the handler’s action method.

1 Like

Thank you for your input it was very helpful, I was able to accomplish what I wanted using the legacy app link you provided.

1 Like