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 Introducing Rewrite Rules

Don Shipley
Don Shipley
19,488 Points

.htaccess

Not sure why but the shirt.php does not open. I get this, Not Found

The requested URL /shirts/shirt.php was not found on this server.

the .htaccess file 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]

3 Answers

Don Shipley
Don Shipley
19,488 Points

found the problem. In his code he writes. RewriteRule ^shirts/([0-9]+)/$ /shirts/shirt.php?id=$1 remove the / before /shirts RewriteRule shirts/shirt.php?id=$1

Works now Thanks...

Great job Don! glad to hear that you managed to solve the problem.

Igor Prymak
Igor Prymak
13,590 Points

Nicely done, man! Worked for me too.

Hi Don,

Remove "shirts" only try using shirts.php instead since you already have the RewriteRule for the directory.

Don Shipley
Don Shipley
19,488 Points

The shirts is the folder with two files. One being shirts.php the other shirt.php. The is the instructors code works on his video but not on my machine. I had to add folders on my root or server directory since I have the files saved in a folder rather than wamps directory of www. <?php define("BASE_URL","/treehouse/php/project02-stage03-shirts4mike/"); define("ROOT_PATH", $_SERVER["DOCUMENT_ROOT"] . "/treehouse/php/project02-stage03-shirts4mike/"); // <?php var_dump($_SERVER[DOCUMENT_ROOT]); // die(); ? The .htaccess file is saved in treehouse/php/project02-stage03-shirts4mike/