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 Get Variables and Rewrite Rules

Umy Ikem
Umy Ikem
21,383 Points

Rewrite rule for get variable(shirt.php?id=) not working

Hi, please i followed this video for get variables and rewrite rules to the letter but i'm still getting a (Object not found error - The requested URL was not found on the server). Here is my code

RewriteRule ^shirts/([0-9]+)/$ /shirts4mike/shirts/shirt.php?id=$1

Not sure why this Rewrite rule is not working as my shirts folder is in the shirts4mike directory and the shirt.php file is in the shirts folder. What am i doing wrong??

3 Answers

Umy Ikem
Umy Ikem
21,383 Points

Thanks for all the help Craig. Seems like it had to do with clearing my browser cache(mozilla). That seemed to do the trick.Cheers

Hi Umy,

Im not sure if I have read the question a little wrong but from what I gather you have a .php file stored in the shirts images folder? From my files from that course the shirt.php file should be in the main fill tree with index.php etc.

If this is not helpful and I have read the question a little wrong below is my code from shirt.php from completion of the course.

<?php include("inc/products.php");

if (isset($_GET["id"])) {
    $product_id = $_GET["id"];
    if (isset($products[$product_id])) {
        $product = $products[$product_id];
    }
}
if (!isset($product)) {
    header("Location: shirts.php");
    exit();
}


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

        <div class="section page">

            <div class="wrapper">

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

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

                <div class="shirt-details">

                    <h1><span class="price">$<?php echo $product["price"]; ?></span> <?php echo $product["name"]; ?></h1>

                    <p>!!PayPal Form would go here!!</p>

                    <p class="note-designer">* All shirts are designed by Mike the Frog.</p>

                </div>  

            </div>

        </div>

<?php include("inc/footer.php"); ?>

Hope this helps or points you towards a solution! :)

Craig

I have just realized you are on the course after the one I completed ... Apologies if this was not helpful :)

Umy Ikem
Umy Ikem
21,383 Points

No problem Craig, my problem is with the rewrite rules. My shirts.php and shirt.php file are working ok but the web server Apache is not seeing the shirt.php file. Probably because there's something wrong with the Rewrite rule but i cant quite figure it out yet...

Found this article Umy not sure if it can help of point you in the right direction :)

link