Posts tagged as ISAPI_Rewrite

CF9 ORM and Apache's mod_rewrite

Here’s another problem I’ve run into with ColdFusion’s ORM (there seem to be a few of these recently…).

I’ve only just started running a CF dev environment under Apache on my Mac – I was previously running IIS under VMWare. The problem comes when using Apache’s mod_rewrite for URL rewriting.

I set up a simple test scenario with the following Application.cfc:

component output="false"
{
	this.name = "ormtest";
	this.sessionManagement = true;
	this.sessiontimeout = CreateTimeSpan(0,5,0,0);
	this.ormEnabled = true;
	this.datasource = "TEST";
	this.ormSettings = {
		cfclocation = "/model"
	};	
}

The model directory contains a single ORM mapping bean, user.cfc.

This runs fine and initialises without a problem. But then I add the following mod_rewrite rules into .htaccess:

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} !/(assets|index.cfm) [NC] 
RewriteRule ^(.*)$ /index.cfm/$1 [NC,L]

This handles rewriting of SES URLs for FW/1 pages – essentially, anything that’s not in the assets folder gets index.cfm/ prepended to it behind the scenes. However, this causes the following error when loading the application:

Could not find the ColdFusion component or interface user.

It turns out that the reference to /model as the ORM’s cfclocation is also being rewritten; what is more, adding model into the RewriteCond of paths to ignore doesn’t solve the problem.

After a bit of searching, I discovered Richard Herbert had experienced what seemed to be the same problem. A quick tweet later, and he told me of the solution he’d found.

The solution is simple: create a mapping to the directory containing the ORM CFCs. So, in my example, I added the following before the ORM settings:

this.mappings = {'/model' = '/Volumes/Dev/Web/sites/ormtest/model'};

…and everything now works as it should. (Note: be sure to change the mapping to reflect the structure of your live server!)

Out of interest, I tried the same test under IIS running ISAPI_Rewrite – and it didn’t share the problem. So I assume that mod_rewrite runs at a lower level in the system than ISAPI_Rewrite: mod_rewrite will rewrite your internal CF file calls. So that’s something to be wary of…

7 comments Posted on 29 August, 2010, in ColdFusion, ISAPI_Rewrite, mod_rewrite, ORM

Useful header in ISAPI_Rewrite: HTTP_X_REWRITE_URL

I've been using ISAPI_Rewrite 3 for some time now to rewrite URLs on my IIS server, and generally to create SEO-friendly URLs.

One thing I only discovered today (and am blogging here mainly for my own future reference) is that for every request, the rewrite engine creates a server variable, HTTP_X_REWRITE_URL, which contains the original requested URL. It was useful for me today, as I was writing a missing page handler, but I can think of many other occasions I've had to create complicated workarounds to work out what the requested URL was.

Read more »

No comments Posted on 2 December, 2008, in ColdFusion, ISAPI_Rewrite

IE6 gzip bug: solved using ISAPI_Rewrite

I've recently turned on gzip compression for all static pages on my web server running IIS6, and am now enjoying faster speeds and lower bandwidth.

However, in my investigations I came across a number of bugs in pre-SP2 IE6 (no surprises there) which means that gzipped CSS and Javascript files can be improperly cached and so intermittently mangled.

Not wanting to turn compression off just because of problems with this (thankfully declining) travesty of a browser, I hit on a way of bypassing compression for the affected browsers.

Read more »

4 comments Posted on 31 October, 2008, in ISAPI_Rewrite