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

Oscar Gomez
Oscar Gomez
2,277 Points

Rewrite rule for Get variable on shirts not working

I have added the following code to my .htaccess file but it doesn't seem to be working and I get a '404 Not Found' error. localhost/shirts/ works however once I go to localhost/shirts/108...I get the error mentioned. Here is my .htaccess code

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

2 Answers

Luis Vazquez
Luis Vazquez
6,370 Points

Hi Oscar,

You're forgetting a "/" after "shirts in the second Rewrite Rule.

Copy and paste this code:

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

Let me know if that works.

-Luis

Oscar Gomez
Oscar Gomez
2,277 Points

Wow, I could not figure it out for my life!

Thanks Luis, that was exactly it!