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 »
10,743 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
InVision App - Prototyping Made Beautiful With Prototyping Tools Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 21, 2012 at 1:58 AM
Updated: Converting A ColdFusion Query To CSV Using QueryToCSV()
Hi Ben, why do you need to have so many double quotes when adding the field and field name to the row data? ----------------------------------------- <cfset LOCAL.RowData[ LOCAL.ColumnIndex ] = ... read »
AXL
May 21, 2012 at 1:24 AM
URL Rewriting And ColdFusion's WriteToBrowser Image Functionality (CFFileServlet)
@Mounir, Open your lower case URL Rewrite rule and add the following condition. Condition input: {REQUEST_URI} Check if input string: Does Not Match the Pattern Pattern: ^/CFFileServlet/_cf_ca ... read »
May 20, 2012 at 4:28 AM
Understanding The Complex And Circular Relationships Between Objects In JavaScript
@Will Vaughn I tried your javascript example but got this error:- foo.print is not a function ... read »
May 19, 2012 at 5:37 AM
A Graphical Explanation Of Javascript Closures In A jQuery Context
Thanks for this article, but I fear you missed an important point. If variables in the outer context change, these changes affect the inner anonymous functions as well. That means: if you change the ... read »
May 18, 2012 at 3:39 PM
Parsing CSV Data With An Input Stream And A Finite State Machine
Can you use file upload button with this? and read live? or does the file have to already be on the server saved? ... read »
May 18, 2012 at 1:06 AM
VIRGO (Aug. 23-Sept. 22): Dead On The Money!
A friend of mine and I were arguing about astrology and she told me that he believes in astrology. She hasn't provided me with any evidence that the belief makes any sense to me. She she been telling ... read »
May 17, 2012 at 11:32 PM
Using ColdFusion to Handle 404 Errors (Page Not Found) On Development Server
Very easy the configuration. I read a lot pages and I can't find the solution. I open the administrator and change this Administrator/server settings/Error Handlers/Missing Template Handler and p ... read »
May 17, 2012 at 3:13 PM
LOCAL Variables Scope Conflicts With ColdFusion Query of Queries
I never cease to be amazed that almost EVERY random CF issue I come across lands me on your site. Thank you for documenting your findings for the world. ... read »