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

PHP Enhancing a Simple PHP Application Cleaning URLs with Subfolders Using Root-Relative Web Addresses

Root-Relative URLs - Work in one place but not the other?

I am going through the Enhancing a PHP Application course and learned that adding a / to the beginning of a link makes it root-relative. Why do I need to use ../ in the receipt/index.php file for going back a folder and the / doesn't work for getting to the root directory.

This works: include("../inc/header.php");

This does not: include("/inc/header.php");

Why is that?

include("/inc/header.php"); should be include("../inc/header.php");

2 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

John;

Perhaps this article will help better explain things.

Ken

Jose Platas
Jose Platas
19,745 Points

Hello john,

Well i believe that the reason why it does not work is this.

When you use include("../inc/header.php") it goes up one directory, which is the place where you have you inc folder

When you use include("/inc/header.php") it goes to the root directory of you entire site, this means that if you have the files of your website in a folder call shirts4mike inside your htdocs folder. it will take you off the shirts4mike folder and take you all the way to the root directory, in this case the htdocs

hope this helps