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

Charlie Swing
Charlie Swing
5,408 Points

I cannot get get the .htaccess file to redirect.

I have checked 100+ times for typos and can't seem to figure out why .htaccess won't redirect in WAMP. Any ideas? The redirect worked in the earlier example but when I added the 2nd rewrite rule, I am getting a 404 Not Found Error. My code is below:

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

2 Answers

Placid Rodrigues
Placid Rodrigues
12,630 Points

Hi Elizabeth,

Is your project directory directly inside the www directory or in some sub-directory? In the second case you need to write the full path in your rule. Like this:

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

Hope that helps,


Thanks Placid! That was helpful

Click on Wamp icon and open Apache/httpd.conf and search "rewrite_module".

Look for - #LoadModule rewrite_module modules/mod_rewrite.so

Remove the "#" as above and save the file. Restart all service by clicking on Wamp icon and selecting "Restart All Services"