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!
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

varis darasirikul
10,832 PointsTroubles with Enhancing a Simple PHP Application Challenge task 1 about RewriteRule
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.
and I wrote this but it doesn't work and i dont know why.
RewriteEngine On
RewriteRule ^flavors/$ /all_flavors.php
RewriteRule ^all_flavors.php$ /flavors/%1/? [R=301]
this is link to a Challenge task (task 1)
3 Answers

Chris Dziewa
17,781 PointsIt looks like you need to replace the % sign with a $ sign in this last line: /flavors/%1/? .
The percent sign would be used in relation to a RewriteCond rule that involves query strings. Also you shouldn't need the ? mark since that is also meant for that same type of rule and its function is to prevent the query string from being included in the url. The final product should be like this: /flavors/$1/ [R=301]
Hope this helped!

varis darasirikul
10,832 PointsI tried your answer but it seem to be doesn't work.

Chris Dziewa
17,781 PointsSorry, I just tried that one and realized what happened. You were actually adding too much. Since /flavors/ already references the php file. You only have to reference flavors in the regular expression. Your final line should look like this:
RewriteRule ^flavors$ /flavors/ [R=301]
All you are adding is the slash at the end of flavors.

varis darasirikul
10,832 Pointsthank you.