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?


it's worth noting that you must cycle the IIS service after the web server mappings for the custom extension are added. The WSConfig GUI will prompt you to let it go ahead and restart the webserver, but it's good to know in the event that you ever find yourself doing this manually without wsconfig.


 

 

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 work as a Software Engineer with ColdFusion and Flex, specializing in Linux. Recently I graduated in Professional Digital Photography from CDIA.
More about me

Recent Entries

 
Recent Tweets for Wed July 01..
I'm Twittering This! or Dude..

Recent Comments

 
Posted By Marie Payne:
I really enjoyed those pictures you took in Alaska. Thank you so much for sharing, for I've been ill and had major surgery. I can't get out and do t ...

Posted By Julia:
First time that I see such photos. Too bad that I don't have Photoshop. I have to ask somebody to do them for me.

Posted By Steven Erat:
See also this collection of images from Dewey Mclean of his experience in the Army in the Korean War [link] His photographs and maps are very we ...

recently played

 
Zombie Nation
by Future Shock
on 90's Club Hits Reloaded
90's Club Hits Reloaded, Future Shock

now playing, a plug-in for itunes

Categories

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

Blogs I Read

 
Terrence Ryan
Ben Forta
Ray Camden
Kinky Solutions
Dan Vega
Gary Gilbert
Simeon Bateman
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