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

crystal oakley
crystal oakley
5,709 Points

Cleaning URLs with Rewrite Rules

The challenge asks to add a rewrite rule to add a trailing slash. I can not figure this out.

RewriteRule ^(flavors/[0-9]+)$ /$1/

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

1 Answer

Hi Crystal! I did the RewriteRule section not too long ago and it was really hard for me to wrap my head around. You almost have it. Just remove the /[0-9]+ part and it works. So like this:

RewriteRule ^(flavors)$ /$1/ [R=301] 

I hope this helps!

crystal oakley
crystal oakley
5,709 Points

Worked like a charm. Thanks!

My pleasure! :)