View Full Version : Correct internal links.
This question has been bugging me for a while.
Imagine I have a site with two folders, one of them is called folder (http://example.com/folder) and the other is called directory (http://example.com/directory).
Now I can link from http://example.com/directory to the index.html in the other folder in a number of ways, all following links will work:
a href="../folder"
a href="../folder/"
a href="../folder/index.html"
a href="/folder"
a href="/folder/"
a href="/folder/index.html"
So which is right? And why?
And is any of them wrong? And why?
And which is best? And why?
And would your answer be different whether you used <base href="http://example.com/"> or not?
Enough questions (or is this last one, one too many)? :)
I think a href="/folder/index.html" is the best option because although all browsers should handle the ../ correctly, some spiders do not. As far as including the index.html portion, that is a matter of preference. However, you need to consider what most people who link to the page are likely to write it, since Google considers /folder/index.html and /folder/ as different pages. On my site, I use / for the root (domain.com/) and /folder/index.html for all other folder, and even use a redirect to enforce this, as this seems to be the pattern that people use when creating links, and I can avoid potential dupe content issues that way.
blitzen
05-29-2007, 04:42 PM
Always best to use the entire url:
<a href="http://www.mysite.com/folder/index.html">
barryaj
05-29-2007, 05:14 PM
John,
If your web server is set up to serve index.html as the default load page for the directory, it is proper to use [a href="../folder/"]. The forward slash at the end tells the server that it is a directory being called and it will serve the default load page of the directory. It is considered the same as using [a href="../folder/index.html"]. wige may have a point with the spiders, but I would need more info on it before I stop my own use of it.
[a href="/folder"] and [a href="../folder"] are improper because the server will search first for a page named folder then for a directory named folder.
All of the above will work, but the first two examples are faster and do not make the server do unecessary work.
I am not familiar with why anyone would use [a href="/folder/"] or [a href="/folder/index.html].
blitzen,
The only time it is best to use the entire url is if the link is outside the website. If it is to another page within the website, the full url is requiring a full round trip out and back into your website.
fctoma
05-29-2007, 05:38 PM
I think a href="/folder/index.html" is the best option because although all browsers should handle the ../ correctly, some spiders do not.
What spiders do not handle ../ correctly? I would like to know where you found this and read more about this issue.
I've used a few different linking structures, all seem to work just fine, I haven't really seen any negative affects for any variations. All pages have been spidered and indexed regardless of what style I used.
incrediblehelp
05-29-2007, 08:08 PM
Also using just the folder names allows you to change your default document and page extensions at anytime without affecting your rankaings. Makes design changes much easier.
Orion
05-29-2007, 09:36 PM
/folder/page.ext is generally the best however there are certain server configurations that do not allow that to work.
Using /folder/ only and having a new directory for every page in your site is NOT good. it's another level the spiders and browsers have to try to scan and ends up creating a nightmare down the road for updates and changes. Also against this method is it doesn't allow for logical organization of information on a site.
It is much more logical and easier to use /product_information/category/product_name.ext to organize your site than /product_name/ for each product etc. (granted this may be done via htaccess or dynamically created in the site if it's a shopping cart).
the /folder/ only method sounds great and works on small sites, but I've had 20 or 30 sites I've had to redevelop that had used that method (back about 5 to 10 years ago)... EVERY one of them ranked higer using multiple directories.
my 2cents worth...
DrTandem1
05-29-2007, 09:55 PM
Since you are linking internally, in other words from your site to your site, you do not need the http etc. Therefore, the best method for an internal link is the directory, if the link resides outside that directory and the specific file (page). For instance,
the link resides on this page http://example.com/directory/index.html and the page you want the visitor to find is in the "folder" directory on its Home page, then the link should be:
folder/index.html
You can add the ending "/," to correctly end the URL, but it is not necessary. Putting "../" in the front simply redirects to the root directory, where it would go anyway.
As Incredible mentioned, you can omit the file name as "folder/" and have it default to the index file of that directory. This is handy for printed promotions such as Dell.com/tv. It is easily remembered and defaults to the index file of the directory called "tv."
However, you are asking about internal linking. I believe what Incredible is saying is that you could change from say html to php without changing the link. This is true only if you are defaulting to the index file of that directory. Often, one uses a directory to make design more simple such as with images. While you can place images in any directory, as a site becomes larger, it makes design easier when using specific directories for specific content. You won't have to comb through extra hundreds of files looking for an image, if you keep your images in their own directory.
You must also be sure that the directory's chmod is properly set, if there is no index file for a specified directory. One way will have it display all of the files in that directory as a list of links and the other will be a 403 error (forbidden). Depending on your desires, you may not want to display all of the files in a directory or you may want to do so as a quick way of providing a list of links to some sort of content.
simmo
05-30-2007, 04:06 AM
John,
I am not a fan of full URLs in internal links because it does not make the site portable. By that I mean that I prefer to test a site on a local server before uploading to the Web. If you use the full URL, you will have to edit the relevant pages. Relative links avoid this.
You say that all the methods you mention work. How many browsers have you tried? - You have tried more than one - right?
Thanks everybody: a wealth of information!
I think a href="/folder/index.html" is the best option because although all browsers should handle the ../ correctly, some spiders do not. As far as including the index.html portion, that is a matter of preference.
What spiders do not handle ../ correctly? I would like to know where you found this and read more about this issue.
I've used a few different linking structures, all seem to work just fine, I haven't really seen any negative affects for any variations. All pages have been spidered and indexed regardless of what style I used.
I think the spider problem might occur when you have a base ref set. My suspicion is that when your base ref is set to http://example.com, the spiders think that a link to ../folder/ is a link to http://example.com/../folder/. I am absolutely not sure of this, but it is just an idea.
Having a base ref seems therefore also the best reason to use /folder/ as a link, because then the spider think you are linking to example.com/folder/. Again, not sure on that!
You say that all the methods you mention work. How many browsers have you tried? - You have tried more than one - right?
I tried IE6, IE7 and Firefox.
Thanks again!
The only time it is best to use the entire url is if the link is outside the website. If it is to another page within the website, the full url is requiring a full round trip out and back into your website.
All links are processed by the browser before the request is made to get the page from the server. A complete URL should have little difference in terms of performance compared to a relative URL, except with certain bots.
What spiders do not handle ../ correctly? This is something I have seen from my own server logs. This is not a problem that I have had with the major search engine spiders, but more with specialty spiders, possibly aggregators and other spiders that skip one of the folders. When I switched to absolute links, this seemed to correct the problem.
Also remember that there may be additional considerations. If you use a test server, full URLS will break. If you use templates, root paths (with a slash at the beginning) may be preferable, but if you frequently move sections of the web site or have folder that change name for some reason, ../ links might be the most effective method for you. One of the most important things though is to be consistant, as this will make tracking down and fixing problems much easier as the site grows.
stuart888
05-30-2007, 12:10 PM
I tend to go with relative links, but to an actual file: a href="../folder/index.html". A couple of reasons, one being that it is best to put actual site names with the suffix in to google and yahoo site maps. And it just makes it easier to remember, maintain, and control. Try to keep all your files in the same structure, and a relative link in one sub folder is different than the sub folder below that. If all links are at the same level, you can handle file name changes easier with find and replace.
Stuart
Tiggerito
05-31-2007, 12:43 PM
We have our websites stored on several servers for testing. e.g. I have a copy on my own machine, we have a private server for integration testing and a public server for client testing. And of course the live server.
We want to be able to xcopy websites from one location to another without having to change bits to make them work. With this in mind we have a url policy:
Almost always use relative urls. Do not prepend "/"s as this may have different effects on different servers. Don't use full urls as this will make a test systems jump to the live system.
We often have all our servers reference client images from the live server. This is because this may be a massive amount of data to keep copying around. So in this case the image urls should be full. i.e. include the domian etc. Core design images (e.g. borders, backgrounds) tend to be copied with the website and therefore have relative urls.
I would also agree that folder urls should include the postfixed "/" and default file names should be excluded.
Webnauts
06-07-2007, 01:06 AM
blitzen,
The only time it is best to use the entire url is if the link is outside the website. If it is to another page within the website, the full url is requiring a full round trip out and back into your website.
Correct! But you still can use the base tag which is a great way to save bandwidth and simplify code by writing long URLs, parameterized URLs, and other unsightly URLs only once and out of view. :)