Skip to main content
Inspiring
February 5, 2012
Answered

How do you use relative paths in ColdFusion?

  • February 5, 2012
  • 1 reply
  • 9792 views

I'm having a problem I cant wrap my head around. I have 4 websites that all reside under C:\ColdFusion9\wwwroot\websites\. Unfortunatly, when I use relative paths, it always navigates from wwwroot instead of from that websites folder. I want to make it so that I can use relative paths that are always calculated from the websites root folder instead of the ColdFusion wwwroot folder.

I had a temporary fix to just create a mapping in the CF Administartor. Although, this became a problem because I had to change it everytime I worked on a different website. Also, it would work properly if I used a relative path like (/documents). Instead it would only work if I did a relative path like (./documents).

Can anybody help me solve this? I've spent so much time trying things its not even funny.

I'm using the CF9 Developer Edition with Dreamweaver CS4.

    This topic has been closed for replies.
    Correct answer Dave Watts

    @Dave,

    Dave, I'm starting to understand how this stuff works. When I installed ColdFusion on my Windows 7 machine, I installed the stand alone developer edition. I'm using the built in web server. I am now realizing that this problem is a server problem rather than a mapping problem. I have attached a link below that I beleive is a partial solution to my problem. You actually were involved in that thread as well!

    I moved my websites folder into the root of my C: Drive. I then had to edit the jrun-web.xml file in order to reconfigure where the server looked for my website assets. So, now instead of my URL reading http://localhost:8500/websites/website1/index.cfm it will now read http://localhost:8500/index.cfm. This fixed all my absolute path issues and also mimics my hosting enviroment. AWESOME!

      <virtual-mapping>

        <resource-path>/*</resource-path>

        <system-path>C:/websites/website1</system-path>

      </virtual-mapping>

    However, I still have a problem that you may be able to answer. Since I am developing multiple websites using the same instance of ColdFusion, how do you set it up so that each website operates in this fassion? Right now, if I want to swich what website I'm working on, I have to go back into the jrun-web.xml file's virtual mapping and change the system-path attribute. (See Code Above)

    This doesn't seem like the optimal way to setup my server. Do I need to install IIS or a different web server in order to accomplish this? Is each website supposed to operate on a different port? (8500,8501,etc)

    Keep in mind I'm running the stand alone developer edition of my development PC.

    I really appreciate your help!

    Virtual Mappings: http://forums.adobe.com/message/4046990


    The built-in CF web server only supports one virtual server per CF instance, so you'd have to change that every time you want to work on a separate site, or create a separate instance of CF using Instance Manager in the CF Administrator. You won't have Instance Manager available, since you chose the "standalone" version of CF during the install. If you reinstalled CF to use the multiserver JRun option, you could then install multiple CF instances, and each would have a separate port (8300, 8301, etc). However, that would also consume significantly more resources on your computer.

    The best solution for this is usually to install an external web server, IIS or Apache, and use that with your single CF instance. IIS is a Windows component, so the version of IIS you can use is limited by the version of Windows you're running. If you're running Windows XP you won't be able to use IIS to run multiple virtual servers. Apache will work for this regardless of your OS, but can be a bit more difficult to configure.

    Dave Watts, CTO, Fig Leaf Software

    1 reply

    Inspiring
    February 5, 2012

    When you use relative paths for what? URLs?  CF file resources?

    What's an example of what you're doing and where it's going wrong?

    --

    Adam

    BobKlaasAuthor
    Inspiring
    February 5, 2012

    @Adam,

    I'm using relative paths to include css, javascript, images, other cfm templates etc. I have multiple websites under a folder called websites that is in the wwwroot directory (see below).

    Where I set up my webroot

    ----------------------------------------------------------------

    C:\ColdFusion9\wwwroot\

    Where my websites are located

    ----------------------------------------------------------------

    C:\ColdFusion9\wwwroot\websites\website1\

    C:\ColdFusion9\wwwroot\websites\website2\

    C:\ColdFusion9\wwwroot\websites\website3\

    C:\ColdFusion9\wwwroot\websites\website4\

    Website1 Example

    -----------------------------------------------------------------

    C:\ColdFusion9\wwwroot\websites\website1\index.cfm

    C:\ColdFusion9\wwwroot\websites\website1\css\styles.css

    So, based upon how I have things setup, here is the scenario. Let's say I'm working on website1 and I want to include a css file in my index page (C:\ColdFusion9\wwwroot\websites\website1\index.cfm) using a relative path. If I use the syntax <link href="/css/style.css"> it is not going to find the css file correctly because it will be looking here (C:\ColdFusion9\wwwroot\websites\css\styles.css) instead of (C:\ColdFusion9\wwwroot\websites\website1\css\styles.css).

    Hopefully I explained it a little better. I've never had to deal with this before so I'm not sure if my design is wrong or if I just didn't configure something properly.

    Community Expert
    February 5, 2012

    Let's say I'm working on website1 and I want to include a css file in my index page (C:\ColdFusion9\wwwroot\websites\website1\index.cfm) using a relative path. If I use the syntax <link href="/css/style.css"> it is not going to find the css file correctly because it will be looking here (C:\ColdFusion9\wwwroot\websites\css\styles.css) instead of (C:\ColdFusion9\wwwroot\websites\website1\css\styles.css).

    There are relative paths, and then there are relative paths. What you're using is not a purely relative path, but what Adobe Dreamweaver documentation used to call a "site-root relative" path (and what many other people call an absolute path, even though it's not a fully-qualified absolute path).

    When you begin a path with a slash, it will resolve from your website's root directory. When you omit the slash, it will resolve from the directory in which the requested page that contains the path resides.

    <link href="http://yoursite.com/websites/css/styles.css">   <-- fully-qualified absolute path

    <link href="/websites/css/styles.css">  <-- site-root-relative, or absolute path

    <link href="css/styles.css">  <-- relative path, which will resolve if the page with this tag is in the websites directory

    Dave Watts, CTO, Fig Leaf Software

    Dave Watts, Eidolon LLC