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

Can't use a RewriteRule with a RewriteCond

No matter what I do, I can't get a RewriteCond to work with a RewriteRule. I even used the code from the downloads and I still can't get it to work right. Here's my code for the .htaccess file:

RewriteEngine On
RewriteRule ^shirts/$ /shirts4mike/shirts/shirts.php
RewriteRule ^shirts/([0-9]+)/$ /shirts4mike/shirts/shirt.php?id=$1
RewriteRule ^contact/([A-Za-z])+/$ /shirts4mike/contact/?status=$1
RewriteRule ^receipt.php$ /shirts4mike/receipt/ [R=301]
RewriteRule ^contact.php$ /shirts4mike/contact/ [R=301]
RewriteRule ^shirts.php$ /shirts4mike/shirts/ [R=301]

RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^shirt.php$ /shirts4mike/shirts/%1/? [R=301]

Any ideas why this won't work?

3 Answers

Hi Craig,

Is your .htaccess file in the same directory as your homepage index.php file? What is the address for your local home page on your development server?

For example, after starting my PHP server I enter "localhost/my_shirt_site/" into the address bar.

Yes, my .htaccess file is in the htdocs (MAMP) directory, right there with the index.php file. My Local home page is http://localhost:8888 (I used to have it in a shirts4mike folder, but even when I moved it out of that and removed the /shirts4mike from the RewriteRuie(s), it still didn't work.

The weird thing is that all of the other rules are working perfectly, so I'm completely stumped as to why this isn't working.

I'm having the same problem. Has anyone solved this.