We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


page referer

Medium Priority
Last Modified: 2013-12-20
Is there any equivalent of Request.ServerVariables("URL") in coldfusion i'm trying HTTP_REFERER though it gave me the whole path. I need the page name only

Watch Question

It sounds like you're looking for SCRIPT_NAME, but if that's not right either, you can do a <cfdump var="#CGI#" /> and get all the variable information.


script_name gives me /foldername/filename.cfm.

I'm looking for the file name only
Try ListLast(SCRIPT_NAME,'/')


actually the full path is like below which i've obtain using http_referer


l need to get foldername/filename.cfm

SCRIPT_NAME should return foldername/filename.cfm


yeah, but i'm using frame in the page

so SCRIPT_NAME return foldername/topframe.cfm

i need to get foldername/mainframe.cfm


which i can get using http_referer or path_translator


i'm trying to use  ListSetAt(1,http_referer,'/') but been unsucessfull
<cfset referpath = HTTP_REFERER />
<cfset path = ListLast(referpath,"/") />
<cfset referpath = Left(referpath,Len(referpath)-Len(path)) />
<cfset path = "#ListLast(referpath,'/')#/#path#" />

Then you can use the #path# variable

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

<cfset variables.referpath = CGI.HTTP_REFERER />
<cfset variables.path = ListLast(variables.referpath,"/") />
<cfset variables.referpath = Left(variables.referpath,Len(variables.referpath)-Len(variables.path)) />
<cfset variables.path = ListLast(referpath,'/')&"/"&path />

I will get you all to start using variable scopes correctly and stop overusing #'s in CFSETs ;oD

Another solution to this would be to treat cgi.script_name as a "/" delimited list as mkishline has done and delete the first two list items from cgi.script_name.

<!--- Remove the domain name --->
<cfset variables.refererPath = ListDeleteAt(cgi.script_name,2,"/")>
<!--- Remove the http:// --->
<cfset variables.refererPath = ListDeleteAt(variables.refererPath,1,"/")>

From "http://www.abc.com/foldername/filename.cfm" this will give you "foldername/filename.cfm"

If you're wondering why deleting the list element at position 2 removes the domain name when its actually in position 3 in the list, this is because CF ignores empty list elements.  The // between http: and www.abc.com consitutes an empty list item and is ignored.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.