ColdFusion 404 Handling Makes Sub Domain Redirects Hard

Posted September 19, 2007 at 1:07 PM

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...

Post Comment  |  Ask Ben  |  Permalink  |  Other Searches  |  Print Page




Learning ColdFusion 9 - ColdFusion 9 tutorials, samples, examples, demos

Reader Comments

Sep 19, 2007 at 2:00 PM // reply »
56 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 »
6,516 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 »
6,516 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 »
6,516 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 »
56 Comments

I think Dinowitz is trying to instigate something.


Post Comment  |  Ask Ben

Recent Blog Comments
Nov 22, 2009 at 1:56 AM
Learning ColdFusion 9: Using CFQuery In CFScript Can Enable SQL Injection Attacks
Why adobe would give you script equivalent of cfquery is beyond me. I love cfquery tag because it helps me wriite clean sql, and get away from the horrible jdbc queries If I wanted to write javali ... read »
Nov 22, 2009 at 1:45 AM
Streaming Text Using ColdFusion's CFContent Tag And The Variable Attribute
The reason you would want to do this is to stream. Ack json/xml files to ria clients I used thus technique before because putting json in response stream causes debugging info to come thru As well a ... read »
Nov 21, 2009 at 6:47 PM
Hal Helms - Real World Object Oriented Development, Sarasota - Day Five
@charlie griefer, Thank you.. ... read »
Nov 21, 2009 at 5:15 PM
Using ColdFusion Structures To Remove Duplicate List Values
@Jose Galdamez, Oh heh yeah I didn't paste the whole code. I should have defined the vars -- my bad. It's fixed thou. Thanks. ... read »
Nov 21, 2009 at 4:49 PM
Styling The ColdFusion 8 WriteToBrowser CFImage Output
Great work yet again Ben! Whilst I didn't use this whole code, I copied some of your regex code for a similar problem with the lack of an alt attribute and unescaped ampersands in CFIMAGE for Railo 3 ... read »
Nov 21, 2009 at 1:13 PM
My First ColdFusion Builder Extension - Encrypting And Decrypting CFM / CFC Files
@Ben, Because I am pedantic, I just want to make sure that everyone knows there is absolutely no encryption going on. There is only encoding and obfuscation. The cfencode tool only obfuscates your C ... read »
Nov 21, 2009 at 12:28 PM
Using ColdFusion Structures To Remove Duplicate List Values
@Jody I can't seem to get your code sample to work. If you are still having problems, try this code out and see if it gets you what you wanted. <!--- Comma delimited list with various duplicates ... read »
Nov 21, 2009 at 11:03 AM
Groovy Operator Overloading Does Not Work In The ColdFusion Context
Hi Ben, Thanks for this informative post. Now I am reading ur old posts too ... read »