Exploring Path Info And How It Interacts With ColdFusion And The Browser

Posted July 18, 2007 at 4:11 PM by Ben Nadel

Tags: ColdFusion, Search Engine Optimization

Earlier today, I blogged about using addition URL path information to solve the Save-As problem that crops up when streaming files using ColdFusion and CFContent. IIS puts this extra URL path information into the CGI variable, path_info. Before today, I had never used this, so I thought it would be good to do a little exploration to see how different aspects of ColdFusion, Javascript, and the web client itself are affected by this additional path information.

To test this, I set up a very small test page:

  • <html>
  • <head>
  • <title>Path Info</title>
  • </head>
  • <body>
  •  
  • <cfoutput>
  •  
  • <h3>
  • CGI Information
  • </h3>
  •  
  • <p>
  • Script Name: #CGI.script_name#
  • </p>
  •  
  • <p>
  • Path Info: #CGI.path_info#
  • </p>
  •  
  • <p>
  • Query String: #CGI.query_string#
  • </p>
  •  
  • <p>
  • URL Struct:
  •  
  • <cfloop item="strKey" collection="#URL#">
  • #strKey# : #URL[ strKey ]#
  • </cfloop>
  • </p>
  •  
  •  
  • <h3>
  • Javascript Information
  • </h3>
  •  
  • <script type="text/javascript">
  •  
  • // Define utility method for getting the locaiton
  • // values by property name.
  • function Get( strProperty ){
  • document.write(
  • "<p>" +
  • strProperty + ": " +
  • window.location[ strProperty ] +
  • "</p>"
  • );
  • }
  •  
  •  
  • // Output the Javascript location properties.
  • Get( "href" );
  • Get( "pathname" );
  • Get( "search" );
  • Get( "hash" );
  •  
  • </script>
  •  
  •  
  • <h3>
  • Web Browser
  • </h3>
  •  
  • <p>
  • <a href="./">Same Level</a>
  • </p>
  •  
  • <p>
  • <a href="../">Up One Level</a>
  • </p>
  •  
  • <p>
  • <img src="./5.jpg" width="333" height="500" />
  • </p>
  •  
  • </cfoutput>
  •  
  • </body>
  • </html>

As you can see, this test page simply outputs the ColdFusion CGI values, the ColdFusion URL struct, the Javascript path values, and also demonstrates how the current browser will interact with the path when it comes to relative traversal and image source values.

When I run this URL:

test.cfm

... I get this output:

CGI Information

Script Name: /..../test.cfm

Path Info: /..../test.cfm

Query String:

URL Struct:

Javascript Information

href: http://..../test.cfm

pathname: /..../test.cfm

search:

hash:

The above URL has no additional path information. And, as such, it seems IIS is putting the same path into both the CGI.sciprt_name and the CGI.path_info variable. The rest of the values make sense as this is how you would normally call a web page.

Then, when I run this URL with extra path information:

test.cfm/images/sexy.jpg?download=true#content

... I get this output:

CGI Information

Script Name: /..../test.cfm

Path Info: /images/sexy.jpg

Query String: download=true

URL Struct: DOWNLOAD : true

Javascript Information

href: http://..../test.cfm/images/sexy.jpg?download=true#content

pathname: /..../test.cfm/images/sexy.jpg

search: ?download=true

hash: #content

Now that the URL has additional path information, IIS is putting a different value in the CGI.path_info value. Now, the CGI.path_info value contains the information that came after the ColdFusion template that is being executed. That is very interesting because before today, I always thought that those two values were the same. What's really cool, though, is that even though we used extra path information, the query string still came through properly; not only did CGI.query_string hold the right value, but the URL struct also had the proper name-value data pairs. Very Cool!

ColdFusion seems to play very nicely with this stuff. The real rub comes when interacting with Javascript and the web browser. As you can see, Javascript views the entire path information as the page's pathname. It does, however, properly parse out the query string, which is nice.

What you can't see in my pasted output is that the image did not load. When I right-click on the image and copy its properties, this is what I get:

http://..../test.cfm/images/5.jpg

Using the additional path information makes the browser think it is more levels deep than it really is. While ColdFusion sees us in being in the same directory as test.cfm, the browser thinks that we are in the images directory. So, while this path info stuff is very neat, it does add complexity to calculating relative web paths (assuming you use relative paths like I do).




Reader Comments

Jul 18, 2007 at 6:22 PM // reply »
76 Comments

Yeah what happens is when using that sort of path info for SEO urls or whatever things like JS, CSS, Images etc (pretty much all hrefs/src) that are linked to will get mixed up.

In my case I was using CF to calculate the ../ required up to the app root from the current URL for each request so that I could use a relative path to the root for these sorts of things. Then I started using path info for SEO links and all failed so I found that the easiest way to fix this was to use an absolute URL to the root in all cases, then there is no issue.


Jul 19, 2007 at 7:36 AM // reply »
11,314 Comments

@Shuns,

Yeah, I feel your pain. A lot of my site works on 404 handling. This means there is a big difference in URL between what the browser sees and what the ColdFusion server sees (CGI.script_name). It makes things a lot more interesting :) Like you were doing, I have to use CF to basically recalculate the relative web root:

../../../

At the top of the page processing. Its a pain, but once it is in place, it seems to be working fine. But I am always nervous that something is going to break :D


Jun 1, 2008 at 12:11 AM // reply »
9 Comments

Ben,

"The above URL has no additional path information. And, as such, it seems IIS is putting the same path into both the CGI.sciprt_name and the CGI.path_info variable."

When I was creating a SES CFC to use for a project of mine, I had developed the CFC from Mike Dinowitz's SES URL UDF ... (Fusion Authority ~ Jun 04' ) ... I was thrown for quite a while trying to determine why the variable / value pairs were not showing up in the URL scope ...

It seems that IIS was converting everything to CGI.path_info ...

I ended up using a different UDF ... but, I found it strange that though the URL scope did have the variable / value's in the URL scope ... IIS did not recognize the UDF's translation as such ...

food for thought.


Uwe
Dec 9, 2008 at 5:59 PM // reply »
1 Comments

Ben,

you wrote "The above URL has no additional path information. And, as such, it seems IIS is putting the same path into both the CGI.sciprt_name and the CGI.path_info variable." That's what I experienced too.

So how do I know which URL was requested if both URLs

http://localhost/test.cfm and
http://localhost/test.cfm/test.cfm

lead to the same result

CGI.Script_Name: /test.cfm
CGI.Path_Info: /test.cfm

?

Even the result of the GetHTTPRequestData() is the same for both URLs.


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
Jun 19, 2013 at 2:01 PM
Experimenting With The Amazon Simple Storage Service (S3) API Using ColdFusion
I have coincidentally been beating my head against the S3 API for the last week or so. One big "gotcha" I had to work around was file names and paths containing spaces. Remember to URL Enco ... read »
Jun 19, 2013 at 1:27 PM
Using Slice(), Substring(), And Substr() In Javascript
very good article. By the way IE supports negative values in substr or slice in verson 10. ... read »
Jun 19, 2013 at 11:33 AM
Filter vs. ngHide With ngRepeat In AngularJS
In your assessment, is it correct to say that given a list of say 500 items its more performant to use the `ngHide` method over the `filter` method? ... read »
Jun 19, 2013 at 10:18 AM
ColdFusion Path Usage And Manipulation Overview
Anyone happen to know if the file created by getTempFile will be automatically removed at any point? Nothing mentioned in the docs, and restarting CF doesn't remove them, so it seems it needs manu ... read »
Jun 19, 2013 at 9:41 AM
Working With Inherited Collections In AngularJS
I actually just ran into this same situation with a demo I was putting together. Your implementation of multi-lvl $scope's > Mine :) ... read »
Jun 19, 2013 at 8:17 AM
My Experience With AngularJS - The Super-heroic JavaScript MVW Framework
@Prateek, to match a word or text you should use .toContain('word') that's a jasmine reference. website is : http://pivotal.github.io/jasmine/ ... read »
Jun 19, 2013 at 8:10 AM
My Experience With AngularJS - The Super-heroic JavaScript MVW Framework
Hi Guys, Actually i am doing e2e test of angular js of my project but i am not getting one thing that is how to press enter key through the test when my form is filled as i am not using a button but ... read »
Jun 18, 2013 at 9:20 PM
Mapping AngularJS Routes Onto URL Parameters And Client-Side Events
I couldn't find examples of passing multiple arguments using the when() routing statement so figured out through trial and error that you can pass multiple arguments using the following format: .whe ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools