Get full url (address bar)

Posted on 2004-04-29
Last Modified: 2013-12-24

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.

Question by:maquejph
  • 4
  • 4
  • 2
  • +3
LVL 35

Expert Comment

Comment Utility

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
LVL 17

Expert Comment

Comment Utility
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 ...


Expert Comment

Comment Utility
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,

LVL 17

Expert Comment

Comment Utility
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.

Author Comment

Comment Utility
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
LVL 17

Expert Comment

Comment Utility
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.
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.


Author Comment

Comment Utility
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.
LVL 17

Expert Comment

Comment Utility
for <CFINCLUDE TEMPLATE="../includes/menu_secure.cfm"> use a mapping you create in CF admin for your other do as I told you above.

Author Comment

Comment Utility
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.
LVL 35

Expert Comment

Comment Utility
You should post a question here :

asking for this question to be PAQ/Refund
LVL 17

Expert Comment

Comment Utility
that looks like a brilliant work-around, great work, looks like its easy to.... keep it up..

Author Comment

Comment Utility
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

Accepted Solution

PashaMod earned 0 total points
Comment Utility
Closed, 500 points refunded.
I've also removed the unnecessary comments, thanks for the understanding

Community Support Moderator

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now