URL Rewrite (ISAPI Rewrite) + Error handling

345 views
Skip to first unread message

Eapen

unread,
Mar 30, 2010, 12:51:34 AM3/30/10
to framework-one
I have been trying to get the Helicon ISAPI rewrite to work with this
for a while but haven't had much success. Just wondering if anyone
else had the solution to this.

My site currently works with http://site.com/index.cfm/main/manage

I want to remove the "index.cfm" from the URL to use http://site.com/main/manage
.

After some searching this is what I came up with (from
http://cfwheels.org/docs/chapter/url-rewriting#comment-83)

RewriteEngine On
RewriteRule (^/(assets|flex2gateway|jrunscripts|cfide|cfformgateway|
railo-context|robots.txt|sitemap.xml|rewrite.cfm|404.cfm)($|/.*$)) $1
[L,NC]
RewriteRule ^/(.*)$ /index.cfm/$1 [NC,L]

But when I try to load the URL http://site.com/main/manage - I see the
"main.default" action instead and the URL is /404.cfm?404;http://
site.com:80/main/manage

It looks like IIS's error handler is kicking in even if the index.cfm
file exists and it works just fine with /index.cfm/main/manage

Any clues on what's happening?
Both the index.cfm and 404.cfm files exist and the missing template
handler is set to /404.cfm in CFAdmin. The variables.framework.error
in my application.cfc is set to "main.error" so I am not sure why it
is going to the /404.cfm.


I was also wondering if it is possible to handle the errors with a
template as Ray explains on his site:
http://www.coldfusionjedi.com/index.cfm/2007/12/5/The-Complete-Guide-to-Adding-Error-Handling-to-Your-ColdFusion-Application
or to be more specific to handle the errors using the "onError"
function. I tried it but it didn’t seem to take effect. Does the
variables.framework.error try to handle all conditions?

Thanks for looking into this.

Sean Corfield

unread,
Mar 30, 2010, 1:25:24 AM3/30/10
to framew...@googlegroups.com
FW/1 intercepts ALL cfm requests covered by the same Application.cfc.

Move your 404.cfm file to a subdirectory and add an Application.cfc
with the same this.name setting (but do not extend framework.cfc).
Then update your paths to that subdirectory so 404.cfm is no longer
intercepted by FW/1.

Sean

Eapen

unread,
Mar 30, 2010, 1:34:04 PM3/30/10
to framew...@googlegroups.com
I tried this but with no luck. Perhaps I didn't understand which paths needed to be updated to point to the subdirectory containing 404.cfm

I also added a function "setupRequest" in the Application.cfc as follows

    <cffunction name="setupRequest">
        <cfoutput>test</cfoutput>
        <cfabort>
    </cffunction>

This shows "test" when I try to access
     /index.cfm
     /index.cfm/main/manage
     /

but when I try
     /main/manage

it gives me a "File Not Found: /404.cfm" error which seems like FW/1 doesn't catch the call to "404.cfm".

I hope this makes sense. (fyi... I am using CF8 on IIS 6.) I was hoping this was an issue with the ISAPI rewrite rules I had written. But for SEO purposes, I really need to be able to get rid of the "/index.cfm/" from the URL.

Thanks,
Eapen

Jamie Krug

unread,
Mar 30, 2010, 1:45:02 PM3/30/10
to framew...@googlegroups.com
It sounds like the rewrite is not working. Where is the 404.cfm coming from anyway? Do you have IIS set to use /404.cfm as the custom 404 page? It seems that either IIS or JRun is not finding the requested path (hence the 404), so you'll need to turn on some logging for your rewrite filter and try to figure out where this is all happening.

Or, just for troubleshooting, maybe use the same rewrite on a non-FW/1 sample app that has only an index.cfm file in the root and nothing else, or just an empty Application.cfc (maybe with just a unique this.name set).

This may sound extreme, but honestly it's quite simple: consider just switching to Apache? I did so, on Windows servers, at my last company, and it was quite nice!

Best,
Jamie

--
You received this message because you are subscribed to the Google Groups "framework-one" group.
To post to this group, send email to framew...@googlegroups.com.
To unsubscribe from this group, send email to framework-on...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/framework-one?hl=en.

Eapen

unread,
Mar 30, 2010, 4:30:17 PM3/30/10
to framework-one
Thanks Jamie.

I almost gave up on this but it turns out there was an issue with the
ISAPI rewrite and the IIS was looking for the /404.cfm as the custom
404.cfm page. It was testing with another site that finally made me
spot the difference.

I didn't need the beginning "/" in my ISAPI rules.
i.e.
RewriteEngine On
RewriteRule (^(assets|flex2gateway|jrunscripts|cfide|


cfformgateway| railo-context|robots.txt|sitemap.xml|rewrite.cfm|
404.cfm)($|/.*$)) $1 [L,NC]

RewriteRule ^(.*)$ /index.cfm/$1 [NC,L]

Switching to Apache is tempting but my company has been immersed in
IIS for years and I would have a hard time convincing the switch to
Apache and all involved (including myself) are used to IIS' GUI.

I still am not quite sure on how to activate the 404.cfm in the sub-
directory but I will play around with it and figure it out.

> > On Tue, Mar 30, 2010 at 01:25, Sean Corfield <seancorfi...@gmail.com>wrote:
>
> >> FW/1 intercepts ALL cfm requests covered by the same Application.cfc.
>
> >> Move your 404.cfm file to a subdirectory and add an Application.cfc
> >> with the same this.name setting (but do not extend framework.cfc).
> >> Then update your paths to that subdirectory so 404.cfm is no longer
> >> intercepted by FW/1.
>
> >> Sean
>
> >>  --
> > You received this message because you are subscribed to the Google Groups
> > "framework-one" group.
> > To post to this group, send email to framew...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > framework-on...@googlegroups.com<framework-one%2Bunsu...@googlegroups.com>

Reply all
Reply to author
Forward
0 new messages