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 path not working

I have followed the video where you use the / to direct right back to the root of the server but it doesn't seem to work at all i am currently running MAMP and have followed everything. Everything in the include files such as links and css are just not working at all

header include file

<html>
<head>
    <!-- Gets the value of the variable pageTitle from page its inserted into
        places it as the title of the page -->
    <title><?php echo $pageTitle; ?></title>
    <link rel="stylesheet" href="/css/style.css" type="text/css">
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Oswald:400,700" type="text/css">
    <link rel="shortcut icon" href="/favicon.ico">
</head>
<body>

    <div class="header">

        <div class="wrapper">

            <h1 class="branding-title"><a href="/index.php">Shirts 4 Mike</a></h1>

            <ul class="nav">
                <!-- The if statement checks the value of the variable section on the page that it has been inserted
                        onto depending on the variable it will add the class to the list item-->
                <li class="shirts <?php if ($section == "shirts"){ echo "on";} ?>"><a href="/shirts.php">Shirts</a></li>
                <li class="contact <?php if ($section == "contact"){ echo "on"; }?> "><a href="/contact.php">Contact</a></li>
                <li class="cart"><a target="paypal" href="https://www.paypal.com/cgi-bin/webscr?cmd=_cart&amp;business=QKGCFGLK289HC&amp;display=1">Shopping Cart</a></li>
                <li class="about <?php if ($section == "about"){ echo "on"; }?> "><a href="/about.php">About</a></li>
            </ul>

        </div>

    </div>

5 Answers

Just read another issue like mine to fix this if you have more than one project folder in your htcdocs you have to specify the project name after the slash and then the file i.e.

/shirts4mike/css/styles.css 

or for a single file outside of a folder

/shirts4mike/shirts.php
Bob Sutherton
Bob Sutherton
20,160 Points

Saved me a headache. Thanks!

Kevin Boller
Kevin Boller
13,768 Points

Cool -- had the same issue. Thanks for posting.

Aaron Munoz
Aaron Munoz
11,177 Points

Thanks for taking initiative!

Hi Tunde

your code looks fine to me. have you got all your files in a subfolder in your htdocs folder?? ie when you access your index page do you type in just localhost or localhost/'foldername'?? if you have got your files in a subfolder than the path would be /yourfoldername/css/style.css

I just answered my own question but thanks for the reply though :)

hello Andreas cormack,

i have a question that when we'll type our sub folder name in the link and when we'll upload the full web on the server than we'll upload the files instead of the folder and in this case the links will be broken. So please tell me the solution for this....