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

Giuseppe Elia Brandi
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Giuseppe Elia Brandi
Front End Web Development Techdegree Graduate 69,630 Points

Code Challenge: Cleaning URLs with Rewrite Rules Adding A Trailing Slash 1 of 1

Good day all, I just wonder if somebody can confirm that both the following expressions to this code challenge are right as they pass the code challenge.

If they are both correct which one is best?

RewriteEngine On
RewriteRule ^flavors/$ /all_flavors.php

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


RewriteEngine On
RewriteRule ^flavors/$ /all_flavors.php

RewriteRule ^flavors$ /flavors/ [R=301]

Best Regards.

Giuseppe Brandi

2 Answers

I would say the first one "RewriteRule ^(flavors)$ /$1/ [R=301]". The point of all of this is to not repeat code. With "flavors" it may not be much of a difference but if you have a long url it might make a bigger impact.

Andrew Chappell
Andrew Chappell
12,782 Points

They are both correct. The $1 just captures what is in brackets so they essentially say the same thing. I guess the 1st one is better practice once things get complicated but I'm not an expert.