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

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,

Placid

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"