Welcome to WebmasterWorld Guest from 54.167.46.29

Message Too Old, No Replies

Importance of URL paths in links...?

Using ../.. instead of www.example.com/directory/

     
10:55 pm on Mar 30, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 19, 2005
posts:54
votes: 0


Let's say I have a link going to file.php under directory: "directory" ...

The link code is a href="../../file.php"

Is that going to lead to any indexing problems as opposed to a href="example.com/directory/file.php" ?

10:48 pm on Mar 31, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


I don't like relative URLs, ones that start ../../../etc.

I do like absolute URLs like www.domain.com/folder/folder/ but I don't like to include the full domain every time.

I use a 301 redirect from non-www to www and then relative URLs counting from the root, which is sort-of the same as absolute, but only with reference within the domain: /folder/folder/.

I never include the filename when linking to an index page. I always end any links to folders with a trailing / to avoid the automatic server redirect that happens when you omit it.

2:55 pm on Apr 1, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:July 28, 2004
posts:82
votes: 0


I use nothing but relative addresses, as I can run the sites locally from the harddrive, and also place it on CD.

If you check Google you'll see that the results always have the full URL in the link. Google doesn't have any problem with relative URL's, anymore than your browser does.

3:21 pm on Apr 1, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 7, 2004
posts:929
votes: 0


Follow g1smd advice: always use full URL and the redirect is also a good idea.

Also because, you use PHP, you can easily set a session variable which will should use the ENV variable to get


$http_dir="YOUR.DOMAIN.COM";
// GET URL_ROOT
if(isset($_SESSION["url_root"])) //CHECK IF VAR EXIST
{$url_root=$_SESSION["url_root"];} else {$url_root="http://".$_SERVER['HTTP_HOST']."/".$http_dir."/";
session_register("url_root"); $_SESSION["url_root"]=$url_root;}

So that all my links look like :
echo "<a href='".$url_root."images/blah/blah/page.php'>";

This way, links works in any host/location. Just need to change the two lines in your include.

Hope this help!

5:03 pm on Apr 1, 2005 (gmt 0)

Full Member

10+ Year Member

joined:July 7, 2003
posts:282
votes: 0



I don't like relative URLs, ones that start ../../../etc.
I do like absolute URLs like www.domain.com/folder/folder/ but I don't like to include the full domain every time.

I use a 301 redirect from non-www to www and then relative URLs counting from the root, which is sort-of the same as absolute, but only with reference within the domain: /folder/folder/.

I never include the filename when linking to an index page. I always end any links to folders with a trailing / to avoid the automatic server redirect that happens when you omit it.


Completely agree! ;)


I use nothing but relative addresses, as I can run the sites locally from the harddrive, and also place it on CD.

A easy way to go through this on windows: type on command line:

subst W: "[i]homepage local path[/i]"

then you'll have a virtual hard-disk drive W pointed to your web's local folder. Addresses from the root will be interpreted from W:

I've heard that similar tricks are available on other platforms, but i don't know about them.

Hoping be useful,
Herenvardö

5:18 pm on Apr 1, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 24, 2005
posts:965
votes: 0


Use relative paths wherever possible. Only use absolute paths when you're accessing another server.

Most internal links on the web are relative, crawlers are designed to handle them.

5:31 pm on Apr 1, 2005 (gmt 0)

Full Member

10+ Year Member

joined:Jan 9, 2003
posts:330
votes: 0


I use <base href="http://www.example.com" /> in my header, and href="subfolder1/subfolder2/" for my links. Since this part of the header is included with php, I can change it very easily, run it on my computer, etc. For me it is much more convenient than using something like "../../../subfolder".

Images are all in img/ no matter in which directory they are used.

When testing a new site I can move it to example.com/sandbox and just need to change the base href tag and it works.

8:39 pm on Apr 1, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


>> subfolder1/subfolder2/

>> Images are all in img/ no matter...

I would use:

/subfolder1/subfolder2/ and /img/

Note the subtle difference.

10:50 pm on Apr 1, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 24, 2005
posts:965
votes: 0


/subfolder1/subfolder2/ and /img/

Note the subtle difference.

LOL, hardly subtle.

I totally agree. I wouldn't bank on a spider reading your BASE HREF. In globay's case, it would be wise to use paths from the root.

11:14 pm on Apr 1, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member bigdave is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 19, 2002
posts:3454
votes: 0


With a brand new, unindexed site, it is my experience that Google will index it faster with full URLs, including domain name and absolute path.

Once it is fully indexed, I generally drop the domain part of the URL, yet keep the absolute path.

I will only go with a relative path when the files actually belong together, and if I move them, they will be moved as a unit. For example if /greenwidget/part1/ links to /greenwidget/part2/ I will use "../part2/" in case I decide to move them both to /greenfuzzywidget/ at a later date.

8:06 am on Apr 2, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 23, 2003
posts:801
votes: 0


One of the problems I've found with relative paths is that when writing a custom 404 pages on Apache, the page is served as if it were at the location of the the missing page (for example 4 levels down), whereas (when using relative links), the links on the 404 page back into the site are relative to where the 404 page resides (for example 1 level down).

In this case, a 404 error isn't handled properly - you can get to the custom page and then the navigation doesn't work.

And of course, I did exactly that - and when tested it, I of course typed a duff address like www.example.com/rubbish.html, and of course I was convinced the 404 page was working!

Having said all that, I still use relative links for the rest of the site.
DerekH