Absolute and Relative Paths
By Jennifer Kyrnin, About.com Guide
Writing URLs
When you're creating links to documents and images on the web, you need to think about how you're going to link to them. There are two standard ways to create links:- absolute paths
- relative paths
Absolute Path URLs
Absolute paths are called that because they refer to the very specific location, including the domain name. The absolute path to a web element is also often referred to as the URL. For example, the absolute path to this web page is:
http://webdesign.about.com/od/ beginningtutorials/a/aa040502a.htm
You typically use the absolute path with the domain to point to Web elements that are on another domain than your own. For example, if I want to link to the Graphics Software Guide’s site — I need to include the domain in the URL: http://graphicssoft.about.com/. So a link to her Photoshop review would look like this:
<a href="http://graphicssoft.about.com/od/productreviews/gr/Photoshop.htm"> Review of Photoshop</a>
If you’re referring to a web element that is on the same domain that you’re on, you don’t need to use the domain name in the path of your link. Simply leave off the domain, but be sure to include the first slash (/) after the domain name. For example, my article “How to Create a Web Page with HTML” has the URL:
http://webdesign.about.com/od/beginningtutorials/ss/aasspagehtml1.htm
If I were to link to this URL from another page on my site, I could link to it in this way:
<a href="http://webdesign.about.com/od/beginningtutorials/ss/aasspagehtml1.htm">How to Create a Web Page with HTML</a>
It is a good idea to use absolute paths, without the domain name, on most websites. This format insures that the link or image will be usable no matter where you place the page. This may seem like a silly reason to use longer links, but if you share code across multiple pages and directories on your site, using absolute paths will speed up your maintenance. Relative Path URLs
Relative paths change depending upon the page the links are on. There are several rules to creating a link using the relative path:- links in the same directory as the current page have no path information listed
filename
- sub-directories are listed without any preceding slashes
weekly/filename
- links up one directory are listed as
../filename
- First define the URL of the page you are editing. In the case of this article, that would be
http://webdesign.about.com/od/beginningtutorials/a/aa040502a.htm
- Then look at the directory path for the page. For this article, that is
/od/beginningtutorials/a/
- Get the URL of the page you want to link to. For this example that would be the “How to Create a Web Page with HTML” article:
http://webdesign.about.com/od/beginningtutorials/ss/aasspagehtml1.htm
- And look at the directory path for that page:
/od/beginningtutorials/ss/
- Compare the two paths, to determine how to link to it. From this article I would need to step up one directory from the
/a/
directory and then go back down to the/ss/
directory using the code../ss/aasspagehtml1.htm
. - Write the link:
<a href="../ss/aasspagehtml1.htm">How to Create a Web Page with HTML</a>
But you are saying that the user has to wait a few moments before clicking “ok” for it to work? What about using a confirm() instead of an alert? That way we would have somewhat of a better mechanical turk, because perhaps users would be too quick to click “Ok.” Or maybe add a lot of text that they have to read first?
Hmmm, interesting stuff. Perhaps when I come off of the cold medications I am on I will play with this stuff…
Thanks for the info!
Comment by Jason Bunting — June 18, 2009 @ 11:03 pm
I think using the caching technique we may even be able to get away with no alert and possibly just a blocking while loop or something. I need to do some more testing.
Comment by coderrr — June 19, 2009 @ 4:28 am
Comment by Godfrey Chan — June 19, 2009 @ 10:09 am
Comment by coderrr — June 19, 2009 @ 10:25 am
what’s next?
Comment by coderrr — June 19, 2009 @ 10:47 am
Comment by coderrr — June 21, 2009 @ 11:08 am
Funny, I thought about a while loop too…
Hope this proves to be a solution, I look forward to the conclusion…
:)
Comment by Jason Bunting — June 19, 2009 @ 6:44 am
Pingback by Preventing Frame Busting and Click Jacking (UI Redressing) « coderrr — June 19, 2009 @ 7:46 am
Pingback by Firefox 3 internals, blocking alerts and XMLHttpRequests « coderrr — June 22, 2009 @ 7:25 pm
Anyhow, I have a couple of questions about the holy grail method. I tried implementing this technique in .NET 3.5 with C#. The log-in page for the app contains an iframe that points to the log-in page. The src tag for the iframe contains a query string param that lets the log-in page in the iframe know that it should set the headers as specified so the page will not cache. I also have the version of the log-in page in the iframe contain no frame busting code.
I would think that it this would allow me to not use a redirect page. The theory goes that the log-in page in the iframe is immediately cached by the browser. The parent log-in frame then contains the busting code as shown above.
Anyhow, my attempt does not work. In IE 7/8 you can hear the navigation sound as the page tries to break out but the frame maintains the upper hand.
My questions are this: What purpose does the redirect serve? It seems like the only reason you are using it is that it is cached and would load very, very quickly. Secondly, do you know of any server based attacks that would prevent the holy grail code? I can not find any script on the client’s frames. If there were script I could analyze what it’s doing and see if I could provide more info or perhaps a solution.
Thanks,
Mike
Comment by Mike — July 22, 2009 @ 11:37 am
You said “set the headers as specified so the page will not cache.”, did you mean to say so the page WILL cache?
Yes, the only reason for the redirect is so you can bust with a page which loads extremely fast so that the parent page doesn’t have time to stop the bust.
Even if you have the login page cached, if it has to load/render images, stylesheets, javascripts, etc. You would have to make sure all of those are cahced as well, and even then there will be time to render the page. It might be too slow.
I’d say try it with a very simple redirect page. Also I’d be interested to see the site which is framing you.
Comment by coderrr — July 23, 2009 @ 4:23 pm
Thanks for the reply. I kind of gave up on the whole thing for a bit because there was (and is) a bunch of stuff that we’re working on.
I was making some compliance updates and SEO enhancements to our main website (the one listed). After I relisted with all the major search engines I saw that we had a bunch of backlinks that were all framed. I decided to revisit the issue and saw that I created a flaw in my code.
I revisited my code and cleaned it up, saw the flaw and moved it our main site. It works like a charm. Thanks so much!
Mike G.
Comment by Mike — September 4, 2009 @ 4:31 pm
Comment by AC — March 24, 2010 @ 5:24 am
Pingback by Common Security Mistakes in Web Applications - Smashing Magazine — October 18, 2010 @ 12:46 pm
Pingback by Common Security Mistakes in Web Applications — October 18, 2010 @ 5:38 pm
Pingback by Design and Digital Media » Blog Archive » Common Security Mistakes in Web Applications — October 18, 2010 @ 8:22 pm
Pingback by Common Security Mistakes in Web Applications | LionWebMedia.com — October 19, 2010 @ 8:53 am
Pingback by Common Security Mistakes in Web Applications | Web Design Course Brisbane: Next Course Wed 20th Oct 2010 — October 20, 2010 @ 7:46 am
Pingback by Best and Cheap Solutions - Common Security Mistakes in Web Applications — October 27, 2010 @ 7:33 pm
Pingback by Common Security Mistakes in Web Applications « I.T News & Stuff — December 3, 2010 @ 4:47 am
how is the file structure and which code where. Do i need to triger bust function ?
Comment by Confuzed — May 6, 2011 @ 1:01 pm
Comment by Mezzeric — May 24, 2011 @ 1:49 pm
Comment by filipe — July 16, 2011 @ 5:20 pm
Comment by DemonTed1 — December 15, 2011 @ 6:03 am
Comment by Larry Holmes — January 5, 2012 @ 4:33 am
Comment by gerdnaschenweng — February 10, 2012 @ 2:07 pm