Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Absolute/Relative Links:

I am learning the "Websites 2" track and how to do absolute/relative links. When I take one of my two files from a folder and place into a separate folder, understandably the link looses connection. I am 100% sure I am following the training and adding my appropriate "folder" name to the .html line to form the connection but still Chrome states "website not found" when I click the link. I did notice the following in the bar across the top of the page that when removed does at least direct me properly: Test%20Site/

Any assistance would be greatly appreciated.

8 Answers

Check out this tutorial on how to organize your files and this tutorial about how file paths work.

So I finished the tutorial above provided by James (which was extremely helpful and easy to read by the way). The last paragraph describing "absolute paths" got me thinking. Why do I even ever want to use one? It appears it's just more work should I need to ever move my site for ultimately the same results?

Thoughts anyone?

The most common use of absolute paths for links that are outside your server.

Another example less common example when using a complex CMS and a file is nested several directories deep in a different directory tree, it's easier to use an absolute path try to figure out the relative path would be.

Makes total sense James,

Really thanks so much again for your time and the links. It's really this that keeps me grinding away every day. This whole treehouse model is insanely well put together.

Best regards,

Hi John,

Would you show us your line of code please, so we can see exactly what was your path?

Absolutely Giovanni,

There is a line of code in each page, within each separate folder:

<a href="Site_Two/Another_Page.html">My Link</a>

<a href="Test_Site/index8.html">Go Back</a>

The top line of code is appropriately referencing "Site_Two" which is the name of a folder I created on my desktop (windows) and just added the corresponding Chrome link of "Another_Page"

The second line of code should be doing the same to link back to the original page. This is also a Chrome link within a folder called "Test_Site".

I do think I have noticed the problem. When I click "My LInk" (which is blue) and it goes to "page cannot be found" the line across the top reads as follows:

file:///C:/Users/JohnComputer/Desktop/Test_Site/Site_Two/Another_Page.html

If I try to go back from the second page to the first, same similar issue. You can see it is trying to reference the same folder "before" moving it to the next folder like it should. The line above should not have "Test_Site"/ as a piece. When I remove it the line works just fine when hitting enter.

I hope this painted a picture for you. Let me know if you need any more detail and thanks again!

John

I have some difficulties to follow your explanation ^^. Could you copy/paste your code from the two pages please?

I may take some time to respond, I'll be in a Global Game Jam from now on. I'll try to take some time to answer you if I can.

Thanks again Giovanni,

I'm going to check out some tutorials James sent above also. Here is the exact lines of code for each file:

<a href="Site_Two/Another_Page.html">My Link</a> <a href="Test_Site/index8.html">Go Back</a>

Here is also the corresponding line that goes across the top of the page for each in order also:

file:///C:/Users/Best%20Buy%202504/Desktop/Test_Site/Site_Two/Another_Page.html file:///C:/Users/Best%20Buy%202504/Desktop/Site_Two/Test_Site/index8.html

You will notice when I run my code, it is including the same folder containing the file I just clicked on, but is also trying to route to the other folder with the other file and corresponding code.

Okay, I got the "Go Back" portion to work. It was as simple as adding the ../ before the folder.

I have also created a root folder that I put both folders into within my Sublime 2 program. The code for both files is now this:

<a href="rootfolder/site_two/another_page.html">My Link</a> <a href="../test_site/index.html">Go Back</a>

The second of code is working fine now. That first line still has something wrong

I just kept messing around and figured it out! I still don't know what was wrong but just took the whole file of code from the second file and pasted it. Then just changed the file & folder name of the one line. It worked!

After the 20th time now I'm guessing the spending hours trying to figure one tiny error out, only to realize it was something insanely small and stupid happens often on this "coding" thing...........