ColdFusion 404 Handling Makes Sub Domain Redirects Hard

Posted September 19, 2007 at 1:07 PM by Ben Nadel

Tags: ColdFusion, Search Engine Optimization

My site runs on the handling of 404 Page Not Found IIS errors within ColdFusion. It is through this mechanism that I am able to translate things like:

www.bennadel.com/foo/bar.htm

... into:

www.bennadel.com/index.cfm?dax=foo.bar

This has been really cool for search engine optimization, but has certainly added some complexity to the page load process. What I have in place has been really good. Except now, I want to add a global 301 permanent redirect for users that access the site without the "www" sub domain. This way, Google and other search engines won't think that www.bennadel.com and bennadel.com are not two different sites.

At first, I thought this would be really easy: All I was gonna have to do is put some logic in my Application.cfc OnRequestStart() event method that would check the current URL, do some CFHeader magic, and then return FALSE (such that the rest of the page wouldn't render - an awesome use case for returning FALSE in an Application.cfc event handler). The problem is, since I am using 404 redirects, the "page" that I am actually firing is the error handling page and NOT the page that was original requested by the end user.

Arrrrg! Now, I need to go back an re-evaluate my whole page load process (it's been a long, long time since it was built). I think I can really move some stuff around and make it work a whole lot nicer. It was an experimentation at the time of construction; now, I think I have the understanding to go back and make it sweet-ass-sweet.

Now don't get carried away and tell me I should just use something like ISAPI_Rewrite or Mod-Rewrite (I don't have access to that sort of mumbo-jumbo on my server). I know I can do an easy All-ColdFusion solution; it's just a matter of sitting down and really thinking out the page request process and standardizing the way I refer to variables (ie. Using an internal CGI representation vs. the CGI object).

More to come...




Reader Comments

Sep 19, 2007 at 2:00 PM // reply »
74 Comments

"Now don't get carried away and tell me I should just use something like ISAPI_Rewrite or Mod-Rewrite (I don't have access to that sort of mumbo-jumbo on my server)."

That had me cracking up.


Sep 19, 2007 at 2:05 PM // reply »
11,238 Comments

I like to put out the fires before they start :)


Sep 19, 2007 at 2:39 PM // reply »
26 Comments

OnMissingTemplate() can be used to accept a template request and then load something else in its place or do a 301 if you want.


Sep 19, 2007 at 2:53 PM // reply »
11,238 Comments

Are you trying to make me sad that I only run on a CFMX 7 box - maybe you'd like to kick my dog while you're at it :)

J/K... I can't wait to be on an CF8 machine. Sooo much cool stuff in CF8 (such as OnMissingTemplate()).


Sep 19, 2007 at 2:54 PM // reply »
11,238 Comments

Also, that "kick my dog" thing was a reference to an old ESPN commercial - not sure if anyone will pick up on that :)


Sep 19, 2007 at 2:58 PM // reply »
26 Comments

Use the ionic isapi to handle your redirects


Sep 19, 2007 at 3:50 PM // reply »
74 Comments

I think Dinowitz is trying to instigate something.


Jun 3, 2010 at 7:22 PM // reply »
50 Comments

Is their something I can Insert into the application page, so it redirects the user if the page does not exsists


Jun 7, 2010 at 9:47 PM // reply »
11,238 Comments

@James,

If you are using Application.cfc, CF8+, you should be able to use onMissingTemplate() AND only if they requested a CFM/CFC page. If you request a non-ColdFusion page, however, you either have to rewrite the request (ala mod_rewrite or IIS Mod-Rewrite) or handle it via 404 error handling.


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 17, 2013 at 7:42 PM
HashKeyCopier - An AngularJS Utility Class For Merging Cached And Live Data
Ben - thanks so much for posting these Angular articles and findings, they've been a huge help towards learning one of the more 'complex' JavaScript frameworks out there (IMO). I have been using Angu ... read »
May 16, 2013 at 5:01 PM
UPDATE: Parsing CSV Data Files In ColdFusion With csvToArray()
Your code was the closest thing I've found to obtaining some direction for converting ISO fields to values that CF can translate properly. Thank you for posting! ... read »
May 15, 2013 at 10:37 PM
Very Simple Pusher And ColdFusion Powered Chat
hi id making plz easy ... read »
May 15, 2013 at 6:07 PM
Making SOAP Web Service Requests With ColdFusion And CFHTTP
Ben, you once again saved my bacon at work. Thank you, thank you, thank you! ... read »
May 15, 2013 at 4:15 PM
What If All User Interface (UI) Data Came In Reports?
@Josh, Thanks! @Ben, I definitely recommend the David West book "Object Thinking" I've been quoting from. It goes deeply into the philosophy and history of OO programming. His breadth ... read »
May 15, 2013 at 11:36 AM
Ask Ben: Print Part Of A Web Page With jQuery
I found this helpfull when you need to keep (refresh) the original parent page after closing the iframe child print dialog (Hoping you're not using a form at this time so it won't submit again): On ... read »
May 14, 2013 at 7:13 PM
What If All User Interface (UI) Data Came In Reports?
@Jonah, If there's any books you'd recommend on the subject of domain modelling, I'd love to hear it. I just downloaded the free PDF of "Domain Driven Design Quickly". Figured I'd give it ... read »
May 14, 2013 at 6:57 PM
The UX Of Prototyping: Low-Fidelity Is The New High-Fidelity
@Phillip, I'm not sure I follow what you mean? Are you saying that you looked at the list of widgets provided by the jQuery UI and let that be your style guide? ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools