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

Bob Sutherton
Bob Sutherton
20,160 Points

Having trouble understanding the concept of getting any number of numbers?

I am having trouble understanding the concepts he is introducing in this .htaccess file. It has been unclear to me ever since he introduced this file. What the heck is going on with this?

I could just follow along, copying his code. But I have no idea what I am doing.

More specifically, he is talking about getting numbers as well as any number of numbers?

^shirts/[0-9]+/$

Can someone please explain what is going on here in minute detail?

3 Answers

The '^' at the beginning means to match something that begins with 'shirts/' then the [0-9] means to match any character zero through nine, then the '+' means match the previous character one or more times. So [0-9]+ would match 0, 01, 000, 3334.

Matches would be: shirts/0 shirts/39 shirts/39393921

Bob Sutherton
Bob Sutherton
20,160 Points

Thanks and where are these possible matches coming from?

It's the URL so from your web browser the request goes to the web server. The web server is where this matching is taking place.

Bob Sutherton
Bob Sutherton
20,160 Points

So the url is coming from here:

$output = $output . '<a href="shirt.php?id=' . $product_id . '">';

That line, among others, is inside a function call that happens in the shirts.php file for this project. So if this line matches a number after shirt/ as in

shirt.php?=101

then it will do something magical? Sorry I am utterly confused by this process.

Bob Sutherton
Bob Sutherton
20,160 Points

I don't mean to trouble you with this. I think I just need to watch the video several more times.

Yes exactly. Any number of numbers just means one or more numeric characters.