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 trialPhillip Legault
Courses Plus Student 18,888 PointsEnhancing a Simple PHP Application Rewrite Rules with Query Strings stage video 4 rewrite for shirt 108 is not working
The redirect works for shirts 101 - 107 works fine
RewriteEngine On
RewriteRule ^shirts/$ /shirts/shirts.php
RewriteRule ^shirts/([0-9]+)/$ /shirts/shirt.php?id=$1
RewriteRule ^reciept.php$ /receipt/ [R=301]
RewriteRule ^contact.php$ /contact/ [R=301]
RewriteRule ^shirts.php$ /shirts/ [R=301]
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^shirt.php$ /shirts/%1/? [R=301]
4 Answers
Zahscha Gonzalez
27,775 PointsWhere do you have the .htaccess located? Where is your shirts folder located? Did you verify that there is no extra whitespace in your shirt.php, or in your shirts.php links?
I had to create the shirts4mike folder, have the index.php there as well as the .htaccess file, and every other folder in the root of the directory. It took me several days to figure this out but it worked.
This is how your .htaccess should look like:
RewriteEngine On
RewriteRule ^shirts/$ /shirts/shirts.php
RewriteRule ^shirts/([0-9]+)/$ /shirts/shirt.php?id=$1
RewriteRule ^receipt.php$ /receipt/ [R=301]
RewriteRule ^contact.php$ /contact/ [R=301]
RewriteRule ^shirts.php$ /shirts/ [R=301]
RewriteRule ^(shirts/[0-9]+)$ /$1/ [R=301]
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^shirt.php$ /shirts/%1/? [R=301]
Phillip Legault
Courses Plus Student 18,888 PointsC:\xampp\htdocs\
Phillip Legault
Courses Plus Student 18,888 PointsWhen I add the url http://localhost/shirt.php?id=101 - http://localhost/shirt.php?id=107 I get the correct page http://localhost/shirts/107/. When I add the url http://localhost/shirt.php?id=108 I get http://localhost/shirt/8/ and a 404 error
I would think the problem is in the products.php file however everything looks correct.
Phillip Legault
Courses Plus Student 18,888 PointsYes I can get to shirt 108 from the shirts page