Get full url (address bar)


My problem is with the mappings for developping I have access to a local server that has been mapped with a different virtual mapping.

http://mydevserver:theport/eup/ -> https://thednsname/eup/dev/
http://mytestserver:theport/eup/ -> https://thednsname/eup/test/

So If I use to find the path of my pictures the following:
<img src="/eup/images/img1.gif"> this will work locally but not with the mapping done that expect <img src="/eup/dev/images/img1.gif">. I have no choice for the external name.

So I would like put into Application.cfm a script that will get the url that is into the address bar. I define it as "root" and I have no more problems.

I have problems also if I use relatives path (img src="images/img1.gif") as I must be able to access those images from one (or more) lower level ("/eup/sec/index.cfm")

I hope that I am clear.

Who is Participating?
PashaModConnect With a Mentor Commented:
Closed, 500 points refunded.
I've also removed the unnecessary comments, thanks for the understanding

Community Support Moderator

I am a little confused about the question and why you need it, but have you looked at the CGI variables?

Here are some that may be of interest

CGI.HTTP_HOST - HTTP host name as sent by the client
CGI.CF_TEMPLATE_PATH - Path of Cold Fusion file being executed
CGI.DOCUMENT_NAME - Complete local directory path of the current document
CGI.DOCUMENT_URI - Local path of the current document relative to the web site base directory
CGI.PATH_INFO - Requested file path information as provided by client
CGI.SCRIPT_NAME - Logical path of script being executed
CGI.RUL - URL base
do one thing ...

set images as a virtual directory [web server]  in root of ur project direcotry ... map it to teh folder "/foldername/images"
now when ur refrencing them - use "/images/imagename.gif" .. no matter where ur file is - this way u will never have to bother abt ur pages being moved or mapping changes from local to online server ...

infact the best deal wld be to have ur images in the root folder - then u wont even need to add the virtual direcotry for "/images" ... as everytime u refer a path starting with a forward slasg "/" it picks up the path from root or finds a virtual direcotry with that name ...

let me know ...

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

You can use,


to give you the 'base' url of the page being viewed (ie. ), but I don't think that it was you need to solve this.

You can create a virtual mapping to the EUP folder and then you hsould be able to access your images using <img src="/eup/images/imagename.jpg">.

To create the mapping:
Login into the CFAdmin and then under 'Server Settings', click 'Mappings'.
Add the name '/eup' and map it to the physical location of the 'eup' folder.

Im not sure what the details of your situation are, but using mappings is a good way to  access directories that exist outside you web root or on another server.

I hope this helps,

Usually you set these variables in the application scope, i.e.

<cfscript> = ""; = "mypath/"; = &;

ALWAYS include a trailing slash, that wau you never have to guess later on.

If these variables are not set yet you could derive them from cgi.server_name and cgi.path_name

I ussually do the following

<cfset request.pathRoot = getDirectoryFromPath(getCurrentTemplatePath())>

<!--- check what phase the application is in --->
<cfset position = reFindNoCase("(development|testing|staging|production)", cgi.path_translated, 1, "true")>
      <cfset request.applicationPhase = mid(cgi.path_translated, position.pos[1], position.len[1])>
            <h1>Application mode could not be found!</h1>
            <strong>You need to set this manually</strong>

And based upon where the application is located I set these environment variables.
maquejphAuthor Commented:
I will try to be more clear.

I have 2 server, one for development, one for test. The path were the files are located is the same on both server (see PATH_TRANSLATED). This is very easy to move files from the dev server to the test server avoiding modification of the scripts.
When I have requested to have external access to the server, the reverse proxy manager impose me to use a general url.
So they have mapped on the reverse proxy "https://theirreverseproxyname/eup/dev/" for the server that host the development files and "https://theirreverseproxyname/eup/test/" for the server that host the test version of the application.

I have done a workaround in the Application.cfm. I check the REMOTE_ADDR and depending the ip I receive I set a variable ROOT to "/eup/ers" or "/eup/dev/ers". and then I create other variable prefixed by the ROOT to indicate where the are the images/css/js (CSS=#ROOT#"css/" ...)  But this will only work for 1 server.

I am working with relatives path for the moment, but I have problem with my menu that in include into each files (<CFINCLUDE TEMPLATE="includes/top_menu.cfm">) Into my menu I have to call images and the relative path is changing depending on the folder level.
For index.cfm (<CFINCLUDE TEMPLATE="includes/top_menu.cfm">)
<img align="absmiddle" src="images/secure_ssl_lock_tr.gif" border="0" alt="secure">
for public/index.cfm (<CFINCLUDE TEMPLATE="../includes/top_menu.cfm"> should be
<img align="absmiddle" src="../images/secure_ssl_lock_tr.gif" border="0" alt="secure">

The CGI:
CGI.PATH_INFO  <nothing returned>
CGI.PATH_TRANSLATED /ec/product/applic/webroot/extern/sec/SAN/eup/app_ers/index.cfm
CGI.QUERY_STRING  <nothing returned>
CGI.SCRIPT_NAME /eup/app_ers/index.cfm
CGI.REMOTE_ADDR 1xx.1xx.x.59
CGI.REMOTE_HOST 1xx.1xx.x.59
CGI.URL  <nothing returned>
CGI.DOCUMENT_URI  <nothing returned>
CGI.DOCUMENT_NAME <nothing returned>
The only difference I receive is the REMOTE_ADDR and REMOTE_HOST

For information, I am learning CFM by myself as I have to wait too long to have the hired cfm developper to come and I have deadline in view. So I am sorry if I am not clear or I have ask "rookie" question
put this in your header of all your pages, if your header is an include this should not be an issue for you
<base href="">

and if your images folder is in the root of your site you can call of them like so
<img src="image/myphoto.gif">

you will never ever have to change the img src again only the base href which as I explained to you above is easily done.

If you use dreamweaver you can easily do a global search and replace if you have to.

If this is still not the solution you are after then its not very clear what exactly you want done.
maquejphAuthor Commented:
I will try to define better (sorry its is not easy)
Let says that my webserver is running locally. The dev is using port 6000 and the test port 7000.

http://localhost:6000/eup/                       = c:\webroot\eup\
http://localhost:6000/eup/app_ers/          = c:\webroot\eup\app_ers\
http://loaclhost:6000/eup/app_ers/img/   = c:\webroot\eup\app_ers\img\
http://loaclhost:6000/eup/app_ers/inc/    = c:\webroot\eup\app_ers\inc\
http://loaclhost:6000/eup/app_ers/sec/   = c:\webroot\eup\app_ers\sec\
http://loaclhost:6000/eup/app_ers/pub/   = c:\webroot\eup\app_ers\pub\

The organisation here using a reverse-proxy to map to all the webserver. So they have mapped as follow: https://the-reverse-proxy/eup/dev/  = http://localhost:6000/eup/ and https://the-reverse-proxy/eup/test/ = http://localhost:7000/eup/

Now, into my file that are located under "/eup/app_ers/sec/" I call StyleSheet/IMGs/INCs
<link href="../css/style.css" rel="stylesheet" type="text/css">
<img src="../images/outlook_mail.jpg" >
<CFINCLUDE TEMPLATE="../includes/menu_secure.cfm">
without problems. Up to me to provide the right relative path.

I use this include in different folder level.
"/eup/app_ers/pub/index.cfm", "/eup/app_ers/index.cfm", "/eup/app_ers/sec/index.cfm"
So depending on the folder hiearachy where the file tha invoke the INCs the path to the images change => "images/outlook_mail.jpg" or ="../images/outlook_mail.jpg"

So whatever I do on the webserver I am bind to the reverse-proxy urls. If I map to have "/IMG_ERS/" to refers to "/eup/app_ers/img/" this will not work with the reverse proxy.


PS: English is not my mother tongue so it is a little more difficult to explain.
for <CFINCLUDE TEMPLATE="../includes/menu_secure.cfm"> use a mapping you create in CF admin for your other do as I told you above.
maquejphAuthor Commented:
I have found a workaround...
In each folder I have created an cfg.cfm that I CFINCLUDE on the first line of each page.
So in the "/eup/app_ers/sec/" it contains
<CFSET IMG_LOC="../images/" >
<CFSET CSS_LOC="../css/" >
<CFSET JS_LOC="../js/" >
<CFSET INC_LOC="../includes/" >
<CFSET PUBLIC_LOC="../public/" >
<CFSET REF_DOC_LOC="ref_docs/" >
So in the "/eup/app_ers/pub/" it contains
<CFSET IMG_LOC="../images/" >
<CFSET CSS_LOC="../css/" >
<CFSET JS_LOC="../js/" >
<CFSET INC_LOC="../includes/" >
<CFSET SECURE_LOC="../secure/" >
<CFSET REF_DOC_LOC="ref_docs/" >
So in the "/eup/app_ers/" it contains
<CFSET IMG_LOC="images/" >
<CFSET CSS_LOC="css/" >
<CFSET JS_LOC="js/" >
<CFSET INC_LOC="includes/" >
<CFSET PUBLIC_LOC="public/" >
<CFSET SECURE_LOC="secure/" >

This is solving my problem.

By the way, thank you for your differents suggestions.
You should post a question here :

asking for this question to be PAQ/Refund
that looks like a brilliant work-around, great work, looks like its easy to.... keep it up..
maquejphAuthor Commented:
Thank you for all your tips.
For the workaround I use; As the path should not be changed and the number of folder that contains pages will not be more than 4, so it will be easy to maintain.

I will do so
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.