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 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!