Skip to main content
August 18, 2010
Answered

Navigation Issue

  • August 18, 2010
  • 1 reply
  • 803 views

Hi All -

I have a directory structure as follows:

folder1
- Includes
   - index.cfm

folder2
- index2.cfm

I have some links on index.cfm which on clicking goes to index2.cfm in folder2. I am using javascript, and the action attribute is:
document.forms[0].action = "../folder2/index2.cfm".

The index2.cfm has a button which on clicking goes back to index.cfm. The javascript action is:
document.forms[0].action = "../folder1/includes/index.cfm".

Until this it is working fine.

Once the user is back on index.cfm and clicks the link to go again to index2.cfm, i get the error that folder1/folder2/index2.cfm does not exist. What could be the cause of this?

This topic has been closed for replies.
Correct answer Adam Cameron.

I don't think you are telling the full story here.  URL relativity does not change from request to request.  If you are at within a document at "location A", and there is a URL relative to "location A" that points to a document at "location B", then that relative URL will continue to work unless either doc moves, or the web server is reconfigured.  And I doubt either of those are happening.  The relativity of the URLs are not impacted by how you happened to arrive at the location in the first place (either by browsing directly to it, or arriving at it via a link from somewhere else).

That said, I suspect what your problem is is that you are trying to make a URL relative to the CFM template you are currently looking at, not the URL that calls the CFM template.  URLs are relative to other URLs, not to the specific file that happens to have the CFM code that renders the link.

EG: if the URL is /subdir/index.cfm, and this in turn includes /inc/someOtherFile.cfm, then URLs within /inc/someOtherFile.cfm still need to be relative to /subdir/index.cfm, not /inc/someOtherFile.cfm.  URLs are an HTTP conceit, they're nothing to do with the file structure of your CF application.

--

Adam

1 reply

Inspiring
August 18, 2010

I would expect you to have got the error right from the outset on any link on index.cfm that tries to go to "../folder2/index2.cfm".  Because - from your sample file structure - the path from index.cfm to index2.cfm is "../../folder2/index2.cfm".  ".." just takes you back to the folder1 dir, and so "../folder2/index2.cfm" resolves to "folder1/folder2/index2.cfm".  You need to go back to the dir above folder1 & folder2 to have a relative path between them.

--

Adam

August 18, 2010

When I try using "../../folder2/index2.cfm", i get error the first time that the requested url is not found but when the user comes back to index.cfm from index2.cfm, the above link works...

Update:

The above two folders are located in one main folder:

Main Folder

- folder1

     -Includes

        -index.cfm

-folder2

       -index2.cfm

Adam Cameron.Correct answer
Inspiring
August 18, 2010

I don't think you are telling the full story here.  URL relativity does not change from request to request.  If you are at within a document at "location A", and there is a URL relative to "location A" that points to a document at "location B", then that relative URL will continue to work unless either doc moves, or the web server is reconfigured.  And I doubt either of those are happening.  The relativity of the URLs are not impacted by how you happened to arrive at the location in the first place (either by browsing directly to it, or arriving at it via a link from somewhere else).

That said, I suspect what your problem is is that you are trying to make a URL relative to the CFM template you are currently looking at, not the URL that calls the CFM template.  URLs are relative to other URLs, not to the specific file that happens to have the CFM code that renders the link.

EG: if the URL is /subdir/index.cfm, and this in turn includes /inc/someOtherFile.cfm, then URLs within /inc/someOtherFile.cfm still need to be relative to /subdir/index.cfm, not /inc/someOtherFile.cfm.  URLs are an HTTP conceit, they're nothing to do with the file structure of your CF application.

--

Adam