Steven Erat's Blog
 
 
Viewing By Entry
 
 

TalkingTree  Configuring ColdFusion to process requests with custom file extensions

 

Technote 18289 describes how to configure ColdFusion MX to handle custom template extensions such as .dbm. The technote is outdated and this blog entry will show you how to configure a custom extension for ColdFusion MX 7. On some occasions I've been asked how to alter the template extension handling in order to mask that ColdFusion runs the web application, so this procedure could be used to even map .htm extensions to ColdFusion.

  • Configure the webserver by using the wsconfig.jar's -map switch with a comma separated list of extensions in quotes, such as -map ".htm,.html". ColdFusion ships connector installation scripts in the cf_root/bin/connectors/ directory that can help facilitate using the wsconfig utility. You could edit the script IIS_connector.bat provided for you so that it uses the -map switch like this:
    %CFUSION_HOME%\runtime\bin\wsconfig -server coldfusion -ws IIS -site 0 -coldfusion -cfwebroot -map ".htm,.html" -v
  • After using wsconfig with the -map switch or using the modified IIS_connector.bat script, the web server is configured to send those extensions to the ColdFusion server, but CF has no internal mapping for them to associate them with the underlying engine, the CFMServlet.
  • If a request for index.htm was made at this point, IIS would hand off the request to the connector, but the connector would have a list of mappings that it got from ColdFusion's web.xml file, and since web.xml does not yet contain mappings for .htm, the result will be that the connector returns an HTTP 503 status code to the web server and the web server sends that to the client browser.
  • Add the internal mappings by backing up and then editing cf_root/wwwroot/WEB-INF/web.xml to create new custom mappings that associate the extensions with the CFMServlet.
  • Use an existing mapping from web.xml as a starting point, like this one:
    <servlet-mapping id="macromedia_mapping_8">
       <servlet-name>CFMServlet</servlet-name>
       <url-pattern>*.cfm</url-pattern>
    </servlet-mapping>
  • Just after the last servlet-mapping node, copy the starter code into the file, and then and change the *.cfm extension in the url-pattern element to a custom mapping like *.htm or even *.foo, and finally remove the id attribute:
    <servlet-mapping>
       <servlet-name>CFMServlet</servlet-name>
       <url-pattern>*.htm</url-pattern>
    </servlet-mapping>
  • Then copy and paste that custom mapping to create a variation on the URL Pattern, ending in /* like this:
    <servlet-mapping>
       <servlet-name>CFMServlet</servlet-name>
       <url-pattern>*.htm/*</url-pattern>
    </servlet-mapping>
  • Repeat for each custom mapping such as .dbm, .htm, etc... Each custom mapping will require two servlet-mapping nodes, one for *.ext and another for *.ext/* (where the *.ext/* mapping helps map Search Engine Safe URLs such as /blog/index.cfm/2006/2/17/CF-Custom-File-Extensions for example)
  • Save web.xml
  • Restart the ColdFusion server AND restart the web server.

 


Comments

Btw, the url pattern doesn't need to contain a file extension. Actually, the url pattern can also be a "directory": /foo/*. This way you can easily create URL that look like deep links but are actually passed to one single CF page.


hey... thats what i said :)

http://www.revolutionwebdesign.com/blog/index.cfm?...

funny how its ALMOST the same entry.


All I get is the following error:

Error Occurred While Processing Request
/ by zero

Anyone else receive this error?


I have tried this and can verify that this does work...but has anybody verified whether or not the security sandbox still operates correctly on these file types. As far as I can tell, it breaks it.


Wow - very impressive site Steven. Thank you - for the resources!!
I'd suggest it's worth mentioning that the 1st step above would configure the server to give ALL *.xml file requests to ColdFusion for processing. I myself reserve CF processing of *.xml files for very special cases. Thus I use the entries you show in the web.xml file but configure each directory individually as required in IIS. For example the default behavior for http://somesite.com and its subdirectory's where one may or may not find static *.xml files. But then add the jrun executable for the extension *.xml on the directory \XML in IIS.


Brian,

Where you say "to give ALL *.xml file requests to ColdFusion", I think you mean .htm file requests (not .xml) since that's the example extension I used in the blog entry.

You're right that its possible to control extension mapping on a per directory level rather than globally. IIS can have the properties for directories and files override any inherited properties.


Thank you for your code sample, this is exactly what I was looking for. Any way to make it only process specific websites sites on the server and not all .html files on the server?


 

 

Calendar

 
Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Search This Site

 
This is an exact search only

About This Site

 
I live west of Boston and used to work at Adobe with ColdFusion and Flex, specializing in Unix & Linux. I recently graduated from CDIA in Pro Digital Photography. Curious about my banner image?

More about me

Recent Entries

 
Christmas Eve Service makes F..
How To Filter by File Type in..
Perspective on ColdFusion's B..
Power Mac G5: The lights are ..
My Application to CDIABU in R..

Recent Comments

 
Posted By Andy Allan:
Fantastic work Steve.

Posted By charlie arehart:
Oh wow, awesome to hear that the relative quiet was an imposed one, and that the gag order has been lifted. Now I'm really excited to hear what may co ...

Posted By Steven Erat:
Thanks for your encouragement Charlie. I have to say that even though I'm trying to be positive and use this time to improve my web skills, most of t ...

recently played

 
Snap Judgments
by WNYC, New York Public Radio
on On The Media
On The Media, WNYC, New York Public Radio

now playing, a plug-in for itunes

Categories

 
RSS Adobe (31)
RSS Bicycling (9)
RSS Blogging (37)
RSS Books (13)
RSS Breeze (12)
RSS CFMX Podcasts (10)
RSS ColdFusion (420)
RSS Computer Technology (50)
RSS Events (25)
RSS Flash (3)
RSS Flex (18)
RSS Gadgets (10)
RSS HiTech Industry (16)
RSS Java (25)
RSS Learning (57)
RSS Linux (70)
RSS Mac OS X (22)
RSS Macromedia (28)
RSS Meetup (34)
RSS New England (62)
RSS Odds & Ends (25)
RSS Outdoors (32)
RSS Personal (29)
RSS Photography (109)
RSS Photoshop (29)
RSS Podcasts (18)
RSS Rants (19)
RSS Restaurants (8)
RSS Science (34)
RSS Spain (16)
RSS Travel (42)
RSS Video (20)
RSS Webcam (3)
RSS Writing (10)

Blogs I Read

 
Scrum Sucks
Ben Forta
Ray Camden
Kinky Solutions
Gary Gilbert
Red Hat Blogs
O'Reilly Digital Media
O'Reilly Radar
John Nack
The Strobist
Scott Kelby
Matt Kloskowski
Joe McNally
Digital Photography School
Engadget
Science Blog

RSS

 


Add to Google
Add to My Yahoo!

Aggregated By

 


Consumed By Feed-Squirrel.com
Aggregated by ColdFusionBlogger.org

Credits and Stuff

 
BlogCFC - Free ColdFusion Powered Blog Software
CJM Group - ColdFusion Website Hosting


 
 
blog | photos | flickr | referers | webcam | stats | about | contact
 
Copyright © 2009 Steven Erat. All rights reserved.
This is a personal weblog. The opinions expressed here represent my own and not those of my employer