Forum Moderators: open

Message Too Old, No Replies

Why do some sites use ../ when linking to a page or image?

         

Synthetic

11:33 pm on Dec 2, 2003 (gmt 0)

10+ Year Member



I see some sites using ../ in their code when linking to a page or image.

For example:

../images/pic.gif
../page/index.html

What exactly is the "../" part supposed to do? Is there some sort of benefit of including it?

jbgilbert

11:39 pm on Dec 2, 2003 (gmt 0)

10+ Year Member



../directoy-page is a relative link (relative location from where your browser is currently pointing). This is used heavily by some web development tools such as FrontPage.

Personally, I recommend using the fully URL!

DrDoc

11:45 pm on Dec 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



../ means "go up to the parent directory"

bunltd

11:52 pm on Dec 2, 2003 (gmt 0)

10+ Year Member



relative url's can be handy when you're working between some secured and non-secured pages and want to use the same template/header file/snippet.

If you had the full url as your image source, your visitor would get a warning that not all items on this page are secure - because they'd be http:// not https:// That means no lock icon - it's enough to send many folks running away. Using a relative url keeps that from happening, since it pulls that from the parent document.

LisaB

Purple Martin

12:35 am on Dec 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



../ means "go up to the parent directory"
../../ means "go up two parent directories"
../../../ means "go up three parent directories"
etc

Or you can use the following shorthand:

../ means "go up to the parent directory"
.../ means "go up two parent directories"
..../ means "go up three parent directories"
etc

DrDoc

4:37 am on Dec 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ehm, using shorthand does not work.

sidyadav

5:12 am on Dec 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use "../"s in my scripts, and most programmers prefer that, because it can be uploaded anywhere, and everything will work instead of someone having to change all the URLs in the whole entire script which would be boring.

"./" = Go back 1 depth to the directory
"../" = Go back 2 depth to the directory

Thats how far I get upto, never hear of ".../"s though.

Sid

DrDoc

4:14 pm on Dec 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, "./" points to the current directory.
"../" points to the parent directory.

I have never heard of any shorthand before. And, when tested -- it doesn't work.

txbakers

10:37 pm on Dec 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



New quirk in IIS6.0 though - when using includes :

<!-- #include file=" ../myinclude.asp" -->

IIS doesn't like the ../ syntax. I had to copy my file into that directory so it worked.

DrDoc

10:43 pm on Dec 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



IIS doesn't like the ../ syntax.

And it's not related to anything like using a backslash instead?

jim_w

10:50 pm on Dec 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>><!-- #include file=" ../myinclude.asp" --> <<

I've been living with problems like that from M$ since Windows3.x and C5.1 I stopped updating their development stuff, unless I had to because of new features I needed to make money on, because I got tired and it got to be too much money rewriting everything all the time. Some of the time, I had already put in fixes and would have to go back and take the fixes out to make it work with the new dev. stuff.

Take it from me when it comes to M$ dev. stuff. If it isn't broke, don't get an update just because it is the latest.

nakulgoyal

12:40 am on Dec 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Better to include complete URL's and then u can test your files and links and everything else even locally. I prefer full URL's as well but sometimes you don't want everything to be fetched from the web and for many other reasons, and me and a lot more people use ../ style linking and image calling etc etc etc.

MatthewHSE

3:41 pm on Dec 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe I've been doing something wrong or am misunderstanding this thread, but here's how I normally use relative URL's:

Assume a directory structure like this:

root
--+ public_html
--¦--+ vehicles
--¦--¦-- small_cars
--¦--¦-- trucks
--¦--¦-- motorcycles
--¦--+ food
--¦--¦-- fast_food
--¦--¦-- gourmet

In the following webpage:

http://mydomain.com/food/gourmet/index.html

I'd link to the following image:

http://mydomain.com/vehicles/small_cars/escort.gif

Using the following code:

<img src="/vehicles/small_cars/escort.gif" width="100" height="40" alt="Ford Escort">

No dots or anything; just the backslash. It's always worked for me; but is there a reason I should use the ../ method?

bateman_ap

3:46 pm on Dec 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<!-- #include file=" ../myinclude.asp" -->

I think you can use <!-- #include VIRTUAL="../myinclude.asp" -->

mcavill

3:46 pm on Dec 4, 2003 (gmt 0)

10+ Year Member



IIS doesn't like the ../ syntax.

To make it work on IIS you need to do a virtual include rather than a file include...

<!-- #include virtual = "../myInc.asp" -->

<added>
Doh - Too slow
</added>

txbakers

5:59 pm on Dec 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



that's funny, because I've been using "file" for years!

I'll try that though, since I don't want 4 copies of the connection string floating around.

waynet

8:32 pm on Dec 4, 2003 (gmt 0)

10+ Year Member



No dots or anything; just the backslash. It's always worked for me; but is there a reason I should use the ../ method?
Two reasons that I can think of:

When testing the file locally, if the local file was c:\mysite\small_cars\escort.gif, it not work with /vehicles/small_cars/escort.gif but it would with ../vehicles/small_cars/escort.gif.

If you should ever move /vehicles and /food directies under an /items folder, you wouldn't have to go fixing all those links in all the html files.

Though I've never used it, I think you can get around these limitations also with the base tag.

jranes

5:44 pm on Dec 5, 2003 (gmt 0)

10+ Year Member



There are two big issues here. If you use xenu link slueth to show a site map you will se that it has no idea what ../ means. Google can follow this in html but ink... have no clue.

So pages that are linked to with only ../ might not get indexed.

The reason people use ../ is for development the url could be dev.devdomain.com and production would be www.brandname.com, using ../ relaive url's allows moving the site without a code change.

For the last several years though the accepted norm is to create an application level variable that holds the base url.

So in ms land in global.asa you would have an app var called baseURL="dev.devdomain.com" or baseURL="www.brandname.com".

This is used in code as <img scr="<%=Server.ApplicationVars("baseURL")%>">

richlowe

9:26 pm on Dec 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No dots or anything; just the backslash. It's always worked for me; but is there a reason I should use the ../ method?

The "../" means go up one directory

The "/" means go to the ROOT directory.

Thus "/example1/example2/example.htm" would translate to "http://www.example.com/example1/example2/example.htm"

While "../example.htm" would translate to "http://www.example.com/example.htm" if example.htm were contained in the "example1" directory, and it would translate to "http://www.example.com/example1/example.htm" if it were in the example2 directory.