Reminder - there is more to the CGI scope than what the dump shows

This post is more than 2 years old.

I knew this - but forgot and instead of spinning my wheels when I make the same mistake in a month, I figured I'd quickly blog it to help me remember.

Don't forget when you cfdump the CGI scope, you are getting what is basically a "known" set of CGI variables. There may be additional CGI values available that will not show up.

A good example of this is CGI.redirect_url. When using Apache URL rewriting, that value will contain the original request URL. So if you rewrite foo.cfm to goo.cfm, you can use cgi.redirect_url to return foo.cfm.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Tim Leach posted on 9/3/2011 at 9:32 PM

It there any way, or list to see what the complete list is? Or is it all trial and error?

I'm guessing the CGI scope comes from the web server,so would that be where I'd look to see what information it makes available?

Comment 2 by Seb Duggan posted on 9/3/2011 at 10:35 PM

I found the same thing, but with ISAPI_Rewrite instead of Apache rewriting. The only difference is that the useful URL is CGI.HTTP_X_REWRITE_URL.

I wrote a post about it a while back:

Comment 3 by Raymond Camden posted on 9/3/2011 at 10:48 PM

@Tim: I don't know. You would think it would be available via Java (remember you can get the low level page object via getPageContext()), but I'm not seeing any method that gets everything.

Comment 4 by Jaana Gilbert posted on 9/4/2011 at 1:21 AM

One that is pretty important for me with one client who is has clustered and load balanced servers.


This gives us the correct remote_addr value instead of the network IP (


Comment 5 by Fernando da Silva Trevisan posted on 9/4/2011 at 4:14 AM

So, you can USE a variable in the CGI scope that isn't showing up in cfdump? That's odd - if you can use, I would bet it should appear in the dump!

Maybe looping through the CGI collection instead of dumping?

Comment 6 by Edward Beckett posted on 9/4/2011 at 6:26 AM

This will definitely come in handy as very soon need to do quite a bit of 301 RegEx work on a CF 8 site ...


Comment 7 by Raymond Camden posted on 9/4/2011 at 6:46 AM

@Fernando - my understanding is that the CGI scope you see in the dump (and looping over the collection won't change it - that's what cfdump does under the covers) is based on a set of known common CGI vars.

Comment 8 by Fernando da Silva Trevisan posted on 9/4/2011 at 6:53 AM

"Known" and "common" as in "CGI vars that surely exists among environments", isn't it?

Now I remember reading something about it in the past (about 4-5 years ago), in some studies I did, probably before trying (and passing) my CF6 certification exam... makes sense.

Comment 9 by Raymond Camden posted on 9/4/2011 at 6:54 AM

Yeah. I think I've blogged on this before too. You can also output ANY cgi variable, like cgi.ray. We just output an empty string if there is nothing there.

Comment 10 by Jules Gravinese posted on 9/4/2011 at 9:39 AM

And for those on IIS7, you can get the original request from CGI.HTTP_X_ORIGINAL_URL.

[!--- IIS7 ---]
[cfset request.urlStrings= listToArray(spanExcluding(CGI.HTTP_X_ORIGINAL_URL, '?'), '/')]

Comment 11 by Jules Gravinese posted on 9/4/2011 at 9:43 AM

Forgot to mention... if you wanted to make your app more portable, do this:

[!--- IIS7 ---]
[cfset request.urlStrings= listToArray(spanExcluding(CGI.HTTP_X_ORIGINAL_URL,"?"), "/")]
[!--- ISAPI_rewrite ---]
[cfif CGI.HTTP_X_REWRITE_URL neq '']
[cfset request.urlStrings= listToArray(spanExcluding(CGI.HTTP_X_REWRITE_URL ,"?"), "/")]
[!--- APACHE ---]
[cfif CGI.REDIRECT_URL neq '']
[cfset request.urlStrings= listToArray(spanExcluding(CGI.REDIRECT_URL ,"?"), "/")]

Comment 12 by Ian Turton posted on 9/4/2011 at 2:57 PM

Given the mutually exclusive nature of these (?!) plus the fact that referencing non-existent CGI vars returns an empty string (and exchanging commentary for brevity), the above could just be...

<cfset request.urlStrings= listToArray(spanExcluding(CGI.HTTP_X_ORIGINAL_URL & CGI.HTTP_X_REWRITE_URL & CGI.REDIRECT_URL,"?"), "/")

Comment 13 by MikeG posted on 9/6/2011 at 8:36 PM

If you have one of the older WACK books, there used to be a reference in the back that contained a pretty good list of common, though not neccessarily available everywhere CGI variables. I found it in Appendix D and D.2 in the MX WACK (Sorry Ray)

Comment 14 by Raymond Camden posted on 9/6/2011 at 8:37 PM

Remember - every time you don't buy the latest WACK, I can't afford a new video game.

And I cry.

A lot.

Comment 15 by MikeG posted on 9/7/2011 at 1:56 AM

I do buy the latest WACK, but I keep the old ones too, otherwise my bookshelves don't look like I have been coding CF for as long as I have <grin>; and besides, you don't need book income any more, you are getting rich building Nook apps now and those don't take near as long to write as a book does..