Click to See Complete Forum and Search --> : Linking Problem
tburton
03-05-2005, 08:38 PM
Hi, I'm making a website, but I have a problem with my links. I know what's wrong, but I don't know how to fix it. I have a folder with my webpage, and its contents. However, I also have another folder inside that folder, with some other webpages (it has to be that way, for organization). So, I'm in the main folder, and to get to a file in the secondary folder, I type in
<A HREF = "Folder2/2ndwebpage.html">
Now, how do I link from inside that folder, out to the main folder again? Whenever I put a link in, it assumes that the file is in the secondary folder, and nothing works. What should I do?
It's like this:
W:\Folder1\Folder2
How do I link a file from Folder2 to a file in Folder1?
tburton
03-05-2005, 08:42 PM
I thought that this would work:
W:\Folder1\Webpage1.html
That way, it would know to look in the first folder to see the file, and everything would work. It appeared to work, and I even put it up on the internet, but when I got home and tried to load the webpage on my computer, nothing linked correctly... :(
ray326
03-05-2005, 11:40 PM
From folder2, ..\webpage1.html.
tburton
03-06-2005, 12:06 AM
OK, I'll try it out. Thanks! I was just reading somewhere else, and I found a site that said to do that, as well. That must be the problem.
ray326
03-06-2005, 10:05 PM
It's ok to use it locally but keep in the back of your mind that some web servers will not allow that kind of link due to security concerns.
ViperwithVenom
03-06-2005, 10:13 PM
Internet addresses closely follow the established hierarchy structure you're probably familiar with on your computer's file system. First comes the Internet domain, like www.site.com. Next comes the directories (folders) that contain the file and finally the file's name, with the appropriate file type extension. Each segment of an url is separated with a forward slash.
Yes, there are two different ways to set your links. Absolute links include the full website address, including the http:// and www. bits. Relative links are much shorter and more manageable. Always remember: on the Internet, all slashes go forwards.
For instance, say you have a page called page1.html in the 'links' directory of your site. The absolute href to this page is http://www.site.com/links/page1.html. So, you put that link anywhere on any page, on any site and it will always go to that page on the Internet.
Relative links can only link to a page from the same site. The address is always relative to the position of the second file. If you were linking to that same page from a page in the same directory, the href would be just page1.html. If you were linking from your homepage, i.e. in the root directory, the link would read <a href="links/wikidfiles.html">, as you would have to go into the directory first, and then get the file.
sourcetip: If you name files index.html in your directories, you can make links to these pages by just linking to the directory name. Your browser will always pick up index as the main page for that folder. This means you can condense href="folder/index.html" into href="folder/". The slash tells the browser it should look for a folder, and not a file. Don't forget it!
Linkal Gymnastics
If you need to go down a directory, and then back up into another one, you'll have to understand how your site is laid out. Using HTMLSource as an example, we are now in the 'myfirstsite' section. Have a look at your address bar to see. If we wanted to link relatively to the 'promotion' section, we'd have to go backwards one directory and then into the promotion directory. So the full relative href would be "../promotion/index.html"
See the two dots? They mean 'up directory' towards your root. So no matter how deep into your site you are, you can always come all the way back with a couple of ../../'s. Just count the directories until you're at the right level.
sourcetip: If you want to link to a page that is near the top of your site (not deep in directories), you can start the link with a slash. This means 'start at the root directory'. So, the href above could just be /promotion/. This saves you having to put in loads of ../../s. A link back to your homepage is always href="/"
Outward Links
On outward links (links to other sites), you must always remember to prefix the address with http://. Otherwise, the link won't work, the browser will look for a file called www.yourhtmlsource.com in your site. You will be linking to us, right? You'll be my new best friend if you do, cheeky.
To do this correctly, you're basically just offering an absolute link, like above. So, the correct address to link to would be http://www.yourhtmlsource.com/. Notice the ending slash? That only goes there for directories (i.e. folders) or domain names, as in this example. Don't put a slash after a .html link, just for directories like a .com or an address without a suffix.
Above information taken from:
http://www.yourhtmlsource.com/myfirstsite/basiclinks.html