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

Paul Neumyer
Paul Neumyer
15,301 Points

Need help with Rewrite rules for Shirts.php

I am having trouble with my .htaccess file redirecting /shirts/101/ to the appropriate file at /shirt.php?id=101. The problem is that the links on the shirts.php page just takes me back to shirts/ instead of taking me to the individual shirt page. Can any one help me?

I have made the rules based in the video, but took somewhat of a different approach, and instead of creating a separate folder just dropped off the extensions. Here is what my .htaccess file looks like.

Here is my Project on Github: https://github.com/PaulNeumyer/shirts4mike

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


RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Options +MultiViews

5 Answers

Don Shipley
Don Shipley
19,488 Points

I had to remove the forward / before shirt for it to work for me.

Don Shipley
Don Shipley
19,488 Points

RewriteRule ^shirts/$ shirts/shirts.php

Paul Neumyer
Paul Neumyer
15,301 Points

Don, I am trying to redirect to the individual shirt pages from the Shirts page.

The rule needs to have the back reference in order to redirect the individual Shirt pages /shirts/101/ to /shirt?id=101. That is the problem I am having.

Don Shipley
Don Shipley
19,488 Points

Had the same problem. Another person also had this problem. Never resolved. Have to study more on the .htaccess but have t much on my plate at this time. I think the way the base url is set up to have a forward slash / con fusses the .htacess starting with a / so it will display as a // Tried to view your site and got a message

Reported Phishing Website Ahead! Google Chrome has blocked access to preview.awakenstudio.co. This website has been reported as a phishing website. Phishing websites are designed to trick you into disclosing your login, password or other sensitive information by disguising themselves as other websites you may trust. Learn more

Paul Neumyer
Paul Neumyer
15,301 Points

Don, you can always try to download my code on GitHub and run it locally with MAMP or WAMP.

Don Shipley
Don Shipley
19,488 Points

Try writing an emial to help@teamtreehouse.com with the issue. They may need to change this in there tutorial as well.

Paul Neumyer
Paul Neumyer
15,301 Points

Good idea. I am going to try that approach.