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 Rewrite Rules Introducing Rewrite Rules

Jeff Hoffman
Jeff Hoffman
6,196 Points

Root Relative Path Not Working for config.php

I have been following along exactly with Randy for this section.

I just moved shirts.php from ht-docs to ht-docs/shirts

Now, when I try to reference ht-docs/inc/config.php from shirts.php, it won't work.

<?php 
    require_once("../inc/config.php");
    require_once(ROOT_PATH . "inc/products.php"); 
?>
<?php

    define("BASE_URL","/");
    define("ROOT_PATH",$_SERVER["DOCUMENT_ROOT"] . "/");

It gives me the error message, saying that inc/config.php does not exist in the ht-docs/shirts folder.

The BASE_URL and ROOT_PATH constants should work fine, but, for some reason, it does not understand the root relative command. I have actually seen this before - it is incredibly frustrating.

5 Answers

Jacob Herper
Jacob Herper
94,150 Points

Which folder is your shirts.php located in? ../ is not root relative, but relative to your current path. If shirts.php is located inside the root directory, the path should be "./inc/config.php" or root relative: "/inc/config.php"

Jeff Hoffman
Jeff Hoffman
6,196 Points

I have been messing with it for a little while, and I think I just got it figured out. Thanks, Jacob.

Jeff, I am having the same problem. Would you mind posting your solution?

Jeff Hoffman
Jeff Hoffman
6,196 Points

Hi Ben,

I can't remember exactly what the problem was, but I am pretty sure it was some kind of typo after all. Either I had some kind of misprint in the code or I had actually not placed the file where I thought it was relative to the ht-docs folder.

I remember thinking that root relative stuff really is pretty straightforward. Just make sure everything is correct with actual file names, where they are relative to each other, and how they appear in the code. I wish I had a plain answer for you because I know how frustrating it can be to get stuck on something like that.

Thanks, Jeff. That's always good advice. I'm sure it's something like that. It's just a matter of going over it again and again.