David,

This is how I do it (my UDF)... Root path is the root directory from the
server standpoint (easy to determine if calculated in a given file) and the
CGI object:

The method CleanWebPath() merely makes sure we have "/" as oppossed to  "\"
in the paths.


<cffunction name="CalculateSiteUrl" access="private" returntype="string"
output="no" 
    hint="Calculates the website's root url based on the root folder and the
current url.">
    
    <!--- Define arguments. --->
    <cfargument name="RootPath" type="string" required="yes" />
    <cfargument name="CGI" type="struct" required="yes" />
        
    <cfscript>
      
      // Define the local scope.
      var LOCAL = StructNew();
    
      // Get the http string and server address.
      if (NOT CompareNoCase(ARGUMENTS.CGI.https, "On")){
        LOCAL.HttpPrefix = CleanWebPath("https://"; & ARGUMENTS.CGI.http_host
& "/");
      } else {
        LOCAL.HttpPrefix = CleanWebPath("http://"; & ARGUMENTS.CGI.http_host
& "/");
      }    
    
      // Convert both the root path and the script name to web paths.
      LOCAL.RootPath = CleanWebPath(LCase(ARGUMENTS.RootPath));
      LOCAL.WebPath =
CleanWebPath(LCase(GetDirectoryFromPath(ARGUMENTS.CGI.script_name)));
    
      // Remove the beginning slash of the web root if there is one.
      LOCAL.WebPath = REReplace(LOCAL.WebPath, "^[\\/]{1}", "", "ONE");
      
      // Check to see if we have a web path. If we do not, then we are
already in the
      // root directory which means that we can just return the server name.
      if (Len(LOCAL.WebPath)){
      
        // Start deleting the web path characters until the entire web path
is at the end
        // of the root path (or we have run out of characters). 
        while(
          (Len(LOCAL.WebPath)) AND
          (Compare(Right(LOCAL.RootPath, Len(LOCAL.WebPath)),
LOCAL.WebPath))
          ){
          
          // Check to see if we have a character to delete.
          if (Len(LOCAL.WebPath) GT 1){
            // Delete the right most character of the web path.
            LOCAL.WebPath = Left(LOCAL.WebPath, (Len(LOCAL.WebPath) - 1));
          } else {
            // We are about to run out of characters, so just set to empty.
            LOCAL.WebPath = "";
          }
        }
        
        // At this point, we either have no more web path, or the path that
we do 
        // have should be the webroot of the site (ending with the
appropriate slash).
        // In either case, just return the http prefix with the remainin
webroot.
        return(LOCAL.HttpPrefix & LOCAL.WebPath);      
      
      } else {
        // Just return the http prefix.
      
        return(LOCAL.HttpPrefix);
      }
      
    </cfscript>
  </cffunction> 


......................
Ben Nadel 
www.bennadel.com

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of David Mineer
Sent: Wednesday, May 10, 2006 11:58 AM
To: [email protected]
Subject: [CFCDev] GetDirectoryFromPath()

<cfset APPLICATION.siteURL =
replace(GetDirectoryFromPath("http://"&cgi.server_name&;
cgi.path_info),"\","")>

I see this used alot to determine the site URl.  However, it doesn't seem to
work all the time.  I notice that if you enter anywhere but the main page on
the first request, then this variable will be set to that page.

Is there a better way to determine the site_url no matter what page in the
app you hit first?

--
David Mineer Jr
---------------------
The critical ingredient is getting off your butt and doing something. It's
as simple as that. A lot of people have ideas, but there are few who decide
to do something about them now.
Not tomorrow. Not next week. But today. The true entrepreneur is a doer.


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
[email protected] with the words 'unsubscribe cfcdev' as the subject of the
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting
(www.cfxhosting.com).

An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]





----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]


Reply via email to