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 Adding A Trailing Slash

Trailing slash rewrite rule

I am stumped. I have tried every combination I can think of, based on the pattern from the "shirts/#/" example but also taking into account that there are no query string ID numbers in this code challenge. The syntax for this was not exactly covered in the lesson. I have searched the web for ideas on how to solve, and have not come up with a satisfactory result. I'm sure I'll be all like "D'oh" when I see the answer, but it's presently beyond my reach.

2 Answers

Wade Christensen
Wade Christensen
Treehouse Teacher

I think this is what you're looking for. You want to match "flavors" and add a "/", so you put flavors (everything between the start "^" and end "$" of what you're looking for) in parentheses as a back reference. You then want to add a "/" to what you have back referenced. You do this with "/$1/". "$1" is your back reference and you add a "/" after it. I hope that makes sense. I passed with the code below.

RewriteEngine  On   
RewriteRule ^flavors/$ /all_flavors.php
RewriteRule ^(flavors)$ /$1/ [R=301]

Thanks, Wade. It makes perfect sense, and I must have had a typo in mine.