Get full url (address bar)

Posted on 2004-04-29
Medium Priority
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

ID: 10950396

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

ID: 10952351
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

ID: 10952967
You can use,


to give you the 'base' url of the page being viewed (ie. http://www.mysite.com ), 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,

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

LVL 17

Expert Comment

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

application.info.domain = "www.mydomain.com/";
application.info.webRoot = "mypath/";
application.info.url = application.info.domain & application.info.webRoot;

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

ID: 10957024
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.SERVER_NAME lakota.xx.xxx.xx.xxx
CGI.HTTP_HOST lakota.xx.xxx.xx.xxx:x0x0
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

ID: 10957177
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="http://www.yoursite.com/whatever/">

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.

Author Comment

ID: 10957385
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

ID: 10958066
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

ID: 10958409
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

ID: 10960732
You should post a question here :

asking for this question to be PAQ/Refund
LVL 17

Expert Comment

ID: 10963459
that looks like a brilliant work-around, great work, looks like its easy to.... keep it up..

Author Comment

ID: 10966608
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
ID: 10999710
Closed, 500 points refunded.
I've also removed the unnecessary comments, thanks for the understanding

Community Support Moderator

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
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…
Integration Management Part 2
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

840 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