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
JUAN VARGAS
17,801 PointsServer Paths and Constants, php challenge
HAVING PROBLEM WITH THE EASIEST TASK?
The PHP file below contains code for the page on a website. It is named index.php, and it is located in the htdocs/about/leadership subfolder. The web address for this web page is http://localhost/about/leadership/. The HTML for the page has an anchor tag that is supposed to link to http://localhost/contact/, but it’s broken. Fix that link, using a root-relative web address.
<html>
<head>
<title>Leadership | Shirts 4 Mike</title>
</head>
<body>
<h1>Leadership</h1>
<p><strong>Owner:</strong> ????</p>
<p><a href="../../contact/about/leadership/">Contact</a></p>
</body>
</html>
7 Answers
Eric Palumbo
6,313 Pointsfor part one all you have to do is put a / in front of it.. it should look like this <html> <head> <title>Leadership | Shirts 4 Mike</title> </head> <body>
<h1>Leadership</h1>
<p><strong>Owner:</strong> ????</p>
<p><a href="/contact/">Contact</a></p>
</body> </html>
Kevin Korte
28,149 PointsThink of this file structure carefully.
Localhost is root. It is homebase.
So what your href is saying is go from leadership folder to about folder, from about folder to root(localhost), from root to contact folder, from contact folder to about folder, from about folder to leadership folder.
That's the logic, and reading it out loud might make you realize where your mistake was. That is what I do when I am trying to figure out root relative paths. I say my steps out loud.
So we know we need to go back to folders to get to contact.
So your href should look something like "../../contact"
Kevin Korte
28,149 PointsDid that pass? Your index.php is outside of the questions and your shouldn't even need it. If you link to a folder the server will default to looking for the index file
JUAN VARGAS
17,801 Pointsyes, it did pass. That's why I think the question is not correct?
Kevin Korte
28,149 PointsYou may be right. I'm not sure how strict the program that allows a passing answer. But, at least you are aware of it.
Randy Hoyt
Treehouse Guest TeacherHmmm, this code doesn't pass for me:
<html>
<head>
<title>Leadership | Shirts 4 Mike</title>
</head>
<body>
<h1>Leadership</h1>
<p><strong>Owner:</strong> ????</p>
<p><a href="/contact/index.php">Contact</a></p>
</body>
</html>
If I remove the index.php, then it works. Having index.php would still work technically, but the question asks you to link to the subfolder.
JUAN VARGAS
17,801 PointsRandy, it was strange because I try all possible outcomes and did not work, then I decided to ask the community in the forum and nothing work. so I just try the last possible resource. and it work. which I know it was not the right answer.. my guest would be /contact/ or ../../contact
Randy Hoyt
Treehouse Guest TeacherThe page you want to link to is this:
The question asks you to use a root-relative address. Root-relative links start with a slash, like this:
<a href="/ ...
That slash means that the web address starts at the root of the domain, which is http://localhost/. So these two links link to the same page if the link is on a page at localhost:
<a href="http://localhost/" ...
<a href="/" ...
The first one is an absolute web address, and the second one is a root-relative web address ... but they both link to the same page if the link is on a page at localhost.
To link to the contact page, you could do either of these:
<a href="http://localhost/contact/">Contact</a>
<a href="/contact/">Contact</a>
Both of those links go to the right page in this example. The first one is absolutely, and the second one is root-relative. This question asks you to create a root-relative link, which is the second one.
Does that help?
JUAN VARGAS
17,801 Pointsthis root-relative option was my first try, /contact/ .....but it did not work for me, so I try different methods
Randy Hoyt
Treehouse Guest TeacherHmmm ... I don't know why that didn't work. It should have worked, and it works for me now. Sorry about the trouble!
Kevin Korte
28,149 PointsI'm curious to try. What is the link to this question?
JUAN VARGAS
17,801 Points@Randy Hoyt, by the way you are great, I love this PHP course.
Miriam Moser
4,261 PointsI've tried all of the following.
<li class="contact"><a href="contact.php">Contact</a></li>
<li class="contact"><a href="/contact.php">Contact</a></li>
<li class="contact"><a href="localhost/contact.php">Contact</a></li>
<li class="contact"><a href="htdocs/contact.php">Contact</a></li>
None will link. I've triple checked that my file is named correctly. Any idea what I'm doing wrong? Everything else is working, I just can't link to my contact page.
JUAN VARGAS
17,801 Points@Kevin, Thank you. I Think the question is miss leading... I found the answer..
<html> <head> <title>Leadership | Shirts 4 Mike</title> </head> <body>
<h1>Leadership</h1>
<p><strong>Owner:</strong> ????</p>
<p><a href="/contact/index.php">Contact</a></p>
</body> </html>