CFInclude Problem on GoDaddy

Go DaddyRecently, I was involved in migrating a ColdFusion 7 website running on IIS 6 to GoDaddy’s Windows/ColdFusion hosting. Right off the bat, I ran into a problem with CFInclude.

Here’s a sample of my code before the migration:

<cfinclude template="/includes/pageheader.cfm">

The path here on the IIS server referenced the site root – meaning that the include file would have been found at the path http://www.example.com/includes/pageheader.cfm. This was failing outright on GoDaddy’s server. Previously, this had worked at any level of my site, no matter how many subfolders deep I was.

I tried this revision that worked as long as files were in the root of the site:

<cfinclude template="./includes/pageheader.cfm">

Notice the addition of a single dot in the template path. This revision failed when I tried to use it in any subfolders.

I ended up using the following code to remedy my problems:

<cfset PathMod = '../'>
<cfinclude template="#PathMod#includes/pageheader.cfm">

And for any sub-subfolders, I modified the PathMod variable to have the requisite number of “../” pairs.

Then there was the CSS problem. In my CSS file(s), I had been using a similar path structure for any URL’s. So to include a background graphic I used this CSS:

background: url(/images/NAT-topnavbar-repeater.gif) repeat-x;

Then I read somewhere that CSS URL paths are relative to the location of the CSS file, not to the page it’s linked from. So that meant simply updating all my CSS URL’s to look like this:

background: url(../images/NAT-topnavbar-repeater.gif) repeat-x;

Once I made these changes, the migration was complete.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s