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

jack hamilton
jack hamilton
5,609 Points

Get Variables and Rewrite Rules

Much like this question

https://teamtreehouse.com/forum/get-variables-and-rewrite-rules

I can not get /shirts/108 to work

I've managed to get /shirts working by removing the / at the start like so

RewriteRule ^shirts/$ shirts/shirts.php

But that second one doesn't seem to work.

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

I'm on windows 7 / Chrome/ Sublime / Xampp

2 Answers

Take a really good look at this line

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

See the trailing slash? You're checking for this pattern:

shirts / ([0-9]+) /

so try adding a slash at the end of your url.

/shirts/108/

jack hamilton
jack hamilton
5,609 Points

Huh I kind of assumed it would have accepted it without the trailing / Thanks! Is there a way of doing either with or without that trailing /?

I believe you're going to cover that in a few videos time :)

can you explain why the beginning slash doesn't work for me? I still have my files in a subfolder localhost/shirts4mike2/shirts/

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

is what i could get working, but that might be a problem since its relative?

At this point, have you started on creating root relative constants?

Sorry - I did not see the notification, and started a thread!

https://teamtreehouse.com/forum/redirects-not-functioning-with-subfolder has all of my details, thanks!