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
Charles Gray
19,470 PointsRewriteRule, I cant figure this out
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 tried this:
RewriteRule ^(flavors/[0-9]+)$ /$1? [R=301] in many different combinations and nothing seemed to work.
2 Answers
Ben Rubin
Courses Plus Student 14,658 PointsThe way that your rewrite rule is written, it will match URLs like http://localhost/flavors/102 and http://localhost/flavors/9, but it won't match http://localhost/flavors. You don't want your match pattern to include the forward slash and you don't want it to include the number after "flavors". Remove those two parts from the URL pattern being matched.
As for the /$1? that you're redirecting to, you just need to change one thing. A question mark is used for rewrite conditions (which aren't being used here), so you don't want that. What is the code challenge asking you to add to the end of the URL? Replace the question mark with that character (and fix the URL pattern being matched) and it should work.
Charles Gray
19,470 Pointssweet thanks. I thought I was over thinking it.