Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

Problem with shirt detail URLs

I seem to be having issues with the clean URLs for the shirt detail pages. All the other site pages seem to be working without any problems, but the clean individual product URLs return 404 errors.

Here's the top portion of my code from the products.php include file:

<code>function get_list_view_html($product_id, $product) {

    $output = "";

    $output = $output . "<li>"; 
    $output = $output . '<a href="' .BASE_URL . 'shirts/' . $product_id . '">';
    $output = $output . '<img src="' . BASE_URL . $product["img"] . '" alt="' . $product["name"] . '">';
    $output = $output . "<p>View Details</p>";
    $output = $output . "</a>";    
    $output = $output . "</li>";

    return $output;
}</code>

Here's my shirt.php file:

<code><?php 
require_once("../includes/config.php");
require_once(ROOT_PATH . "includes/products.php"); 
if (isset($_GET["id"])) {
    $product_id = $_GET["id"];
    if (isset($products[$product_id])) {
        $product = $products[$product_id];
    }
} 
if (!isset($product)) {
    header("Location:" . BASE_URL . "shirts/");
    exit();
}

$section = "shirts";
$pageTitle = $product["name"];
include(ROOT_PATH . "includes/header.php"); ?>

        <div class ="section page">

            <div class="wrapper">

                <div class="breadcrumb"><a href="<?php echo BASE_URL; ?>shirts/">Shirts</a> &gt; <?php echo $product["name"]; ?></div>

                <div class="shirt-picture">
                    <span>
                        <img src="<?php echo BASE_URL . $product["img"]; ?>" alt="<?php echo $pageTitle; ?>"
                    </span>
                </div>

                <div class="shirt-details">

                    <h1><span class="price">$<?php echo $product["price"]; ?></span><?php echo $product["name"]; ?></h1>
                    <p class="note-designer">* All shirts are designed by Mike the Frog. *</p>

                </div>  




            </div>

        </div>

<?php include(ROOT_PATH . "includes/footer.php"); ?></code>

Thanks in advance for any help...hopefully I didn't just fail to spot a typo.

1 Answer

Alan Johnson
Alan Johnson
7,625 Points

Hi Stewart! Are you around the part of the course where you're learning about url rewriting as well? What's your htaccess file looking like?