bpurcell.org - Using ISAPI Rewrite with ColdFusion
  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      

Subject Archives
Amazon EC2 (15)
ColdFusionMX (155)
Corvette (3)
Flash Lite (4)
Flash Media Server (5)
Flash Player (3)
Flex (39)
General Web Dev (14)
HDTV (3)
Jboss (1)
Jquery (2)
JRun (59)
Max 2003 (3)
Other (33)
PC Hardware (16)
Software (17)
SpatialKey (7)
Wireless (8)
Working Out (1)

RSS Feed
Feed Listing

Site Contents
My Blog
Wireless & Networking
Hardware & Gadgets
Software Picks
Contact Me

My Articles & Papers
Flex Performance
mm.com Under the Hood
Multiple Instances of CFMX
Multiple Instance Config
NLB with ColdFusion
Clustering CFMX for J2EE
Multi-Tier Hardware LB w CFMX
Cisco CSS & Coldfusion MX
JRun 4 Jini based Clustering
WiFi Growth

2ID Tacweb

Other Hobbys
Body-For-Life Challenge

Personal Projects
Family Pool
Deck Gate


Viewing Individual Entry / Main
November 3, 2005

ISAPI Rewrite is an IIS ISAPI filter that I have recommended in the past in place of the JRun connector to cluster with a hardware load balancer in between the application server and web server. I outlined the usage in the following article. ISAPI Rewrite can also be used in conjunction with the JRun connector for several different useful features.

In order to use ISAPI Rewrite in conjunction with the connector it will need to be loaded as an ISAPI filter with a higher priority than the JRun connector. The ISAPI Rewrite filter examines requests before the JRun connector processes them so we can perform pre processing (rewriting, proxying, or blocking requests) among other things. I will provide a quick overview of the structure of the configuration files for ISAPI rewrite as well. After you install ISAPI Rewrite it installs the ISAPI Rewrite filter into IIS at the master level so that it affects all sites on that server. All configurations that you want to affect all sites will go into c:\Program Files\Helicon\ISAPI Rewrite\httpd.ini. ISAPI Rewrite also allows you to configure individual settings for each virtual site on the server. By placing a httpd.ini file in the webroot of a site the filter will process it as well, the master file will be processed first then the configuration in the virtual site.

Back to the many uses of ISAPI Rewrite, at least ones that I have discovered you may have more to contribute. If you have questions on the regular expressions I am using take a look at the ISAPI Rewrite documentation.

Blocking URL's

I have used this approach to secure web based administration tools including the ColdFusion administrator. If you wanted to prevent external access to the ColdFusion Administrator and allow access behind your firewall on a private IP you could do the following. Enable the JRun Webserver (default instance runs on port 8500) and access the administrator through http://internalIP:8500/CFIDE/administrator/index.cfm. With IIS configured to the JRun server you would still have external access to the administrator. This is where ISAPI Rewrite comes in. Within the httpd.ini file we can add the following rule that blocks external access to /CFIDE/administrator/

#Block ColdFusion Administrator
RewriteRule /CFIDE/administrator.* [F,I,O]

We could also block RDS using this same approach

#Block ColdFusion RDS
RewriteRule /CFIDE/main/ide.cfm.* [F,I,O]

You can use this approach to block any URL all that is needed is a simple regular expression.

Rewriting SES (Search Engine Safe) URL's

The following rule will convert search engine safe (SES) URL to a standard URL so you don't have to handle them in your ColdFusion code.

#Convert SES URLs to standard URLs before passing them to ColdFusion
RewriteRule (.*?\.cfm)(\?[^/]*)?/([^/]*)/([^/]*)(.+?)? $1(?2$2&:\?)$3=$4?5$5: [N,I]
RewriteRule (.*?\.cfc)(\?[^/]*)?/([^/]*)/([^/]*)(.+?)? $1(?2$2&:\?)$3=$4?5$5: [N,I]

For example the following URL gets converted

http://host/page.cfm/var1/value1/var2/value2 -> http://host/page.cfm?var1=value1&var2=value2

Rewriting URL's for SEO optimization

I am not going to go into depth on search engine optimization (SEO) as I could spend a year just writing about it. One of the common things I have found is that a URL with keywords early after the hostname is rated better than including them in the query string at the end. You can create URL's that are easier to read as well and make it look like the pages the user is surfing is static content although it is generated on the fly. The following is not a real world example but I will say that I have used this approach with much success for data drill down applications to get search engines to rate the content highly. I don't want to give away any secrets though :-)

Let say we wanted a search engine to crawl our site for specific keyword that would be common search terms. If this were a dynamic ColdFusion page the URL's would look something like this.


With the following rule in httpd.ini we could rewrite the above URL

RewriteRule /search/(.*)\.htm /search.cfm\?keyword=$1 [I,O]

The following URL's
http://host/search/keyword1.htm -> http://host/search.cfm?keyword=keyword1
http://host/search/keyword2.htm -> http://host/search.cfm?keyword=keyword2
gets rewritten to the URL's that we examined in the beginning, to ColdFusion it doesn't know the difference. We could provide a page with links to all of the common keywords and let the search engine walk through and index them. It may not seem apparent right away how this is such a cool thing but with a little imagination you can use this approach for a lot of things

Rewriting URL's to hide the file extension

This is similar to the example above except we are just hiding the actual file extension. For example we could rewrite .html requests to .cfm requests.

RewriteRule (.*)/(.*)\.html(.*) /$2.cfm [I]

Proxying Requests to Other Hosts

Lets say you had a single web server and host and multiple backend systems that you wanted to integrate through the same hostname. One system running ColdFusion, another system that is servlet based running on Tomcat. Of course you could integrate them but lets assume that is not an option. With J2EE applications you normally have a context root or prefix to every request. Lets assume that we have a context root of /myapp so all requests look like the following http://host/myapp/page.jsp. Lets also assume that this application is running on a different server other than the one ColdFusion or JRun is running on ( on port 8080). The following rule would proxy requests from IIS to the server running our other application.

RewriteProxy (/.*myapp.*) http\://\:8080$1 [I]

Proxying requests to remove the JRun connector

This is the approach I used in my article for JRun clustering with a hardware load balancer in between the webserver and application server. Since the standard protocol for the JRun connector is JRPP it does not work well through a hardware based load balancer. If you are using a context root in your ColdFusion application of / you will need to proxy by extension and can use the following rules. This will handle nearly every extension that CF needs and passes them to the JWS

#Rewrites to proxy requests back to the appserver level (CF)
RewriteProxy (/.*\.cfm.*) http\://\:8501$1 [I]
RewriteProxy (/.*\.cfc.*) http\://\:8501$1 [I]
RewriteProxy (/.*\.jsp.*) http\://\:8501$1 [I]
RewriteProxy (/.*\.jws.*) http\://\:8501$1 [I]
RewriteProxy (/.*\.jst.*) http\://\:8501$1 [I]
RewriteProxy (/flashservices.*) http\://\:8501$1 [I]
RewriteProxy (/.*servlet.*) http\://\:8501$1 [I]
RewriteProxy (/.*CFIDE/GraphData.*) http\://\:8501$1 [I]

One issue I ran into with this configuration is that a request for http://host will not use the default document in IIS of index.cfm so you can use the following rule to map http://host to http://host/index.cfm

#Fix final slash for /dir
RewriteCond Host: (.*)
RewriteRule ([^.?]+[^.?/]) http\://$1$2/ [R]

#Append index.cfm to any dir
RewriteRule ((?!.+\.cfm).*/) $1index.cfm [I,O]

I would like to mention that I do not recommend removing the JRun connector unless you expect to handle supporting this configuration yourself. This approach is not directly supported by Macromedia but it does work as I have used it in the past. Don't expect Macromedia support to assist you with issues regarding this configuration.

It is worth mentioning that I am a big fan of Apache and you can do all of this with Apache and never have to buy a third party plug in. Apache has mod_rewrite and mod_proxy to accomplish the same tasks.


Thanks for the details. I am using isapi rewrite myself and can say only good things about it. Might be worth noting that they have a free version that allows to do most of what you mention.

Thanks Brandon!

Thanks for the info. We've been using isapirewrite for about a year and love it. In addition to using the proxy functions to load balance, we use it to hide the context root. We just recently started using flash forms and are having issues using the flash forms with isapi rewrite. Are there any additional extension we need to be aware of? We added .cfswf and were able to get the form module to load (progress bar in flash) but nothing loads within the flash file. The same code works fine on oru dev servers that do not use context roots and isapirewrite.


Nice article! We use ISAPI re-write on our shared hosting servers and it's fantastic. We use it on some high volume sites with fusebox and FarCry with great results.

I would like create a Rules that can make this :

http://www.domain.com/product_detail.cfm?id=1 -> http://www.domain.com/product_detail_1.htm

or if you have more than one parameter :

http://www.domain.com/product_detail.cfm?id=1&city=miami -> http://www.domain.com/product_detail_1_miami.htm

How to write this rule with ISAPI Rewrite for coldfusion...

Many thanks Neo

Nice. But this can also be done WITHOUT using the ISAPI Rewrite, Just chuck this code is your application.cfm file:

<cfif ListLast(CGI.PATH_INFO,".") NEQ "cfm"> <cfif Find(".cfm",CGI.PATH_INFO)> <cfset lenRHSofDotCFM = Len(CGI.PATH_INFO) - (Find(".cfm",CGI.PATH_INFO)+4)> <cfelse> <cfset lenRHSofDotCFM = Len(CGI.PATH_INFO)> </cfif> <cfif lenRHSofDotCFM GT 0> <cfset RHSofDotCFM = Right( CGI.PATH_INFO, lenRHSofDotCFM )> <cfset numURLItems = listLen(RHSofDotCFM,'/')> <cfset numURLItems = numURLItems - (numURLItems mod 2)> <cfloop from="1" to="#numURLItems#" index="i" step="2"> <cfset URL[ GetToken(RHSofDotCFM,i,'/') ] = GetToken(RHSofDotCFM,i+1,'/')> </cfloop> </cfif> </cfif>

More info here: http://www.cftopper.com/index.cfm?page=blog&blogId=1&blogpostid=16

Greetings! The site is great. Thank you for a great resourcehttp://armadabeauty.com/

Your post is so interesting and informative. I got a lot of useful and significant information. Thank you so much.<a href="http://armadabeauty.com/" rel="dofollow">do follow</a>

Hi, this is a very interesting web page and I have enjoyed read­ing many of the arti­cles and posts con­tained on the web­site, keep up the good work and hope to read some more inter­est­ing con­tent in the future. Thank you so much. <a href="http://www.isapirewrite.com/docs/" target="_blank">ISAPI Rewrite documentation</a>

Page Render Time:234