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
Casey Ydenberg
15,622 PointsRewrite Rules: Adding a trailing slash
I'm stuck on the code challenge about adding a trailing slash. The question is:
In an earlier code challenge, we wrote a rewrite rule so that the web page [http://localhost/flavors/] executed the code at [all_flavors.php]. Unfortunately, this only works if the web address includes the trailing slash. If someone visits [http://localhost/flavors], they will see a 404: Page Not Found error. We'll need another rewrite rule to redirect from [/flavors] to [/flavors/]. Add a new line to the htaccess file below to accomplish this.
I've tried:
RewriteEngine On
RewriteRule ^flavors/$ /all_flavors.php
RewriteRule ^flavors$ /flavors/
and various types of Regex that I think go beyond what was taught. Does the order of the lines matter? Why do we need to redirect to flavors/ if that will just redirect to all_flavors.php (I've tried doing it directly, too)?
Any hints as to what to try?
3 Answers
Nikolaos Papathanassopoulos
10,322 PointsYou did everything right, except you didnt redirect:
RewriteRule ^flavors$ /flavors/ [R=301]
~ Nikos.
KJ Prince
5,145 PointsThis worked for me.
RewriteRule ^(flavors)$ /$1/ [R=301]
ricardogutierrez
11,349 PointsThanks Niko...
all is in the details.