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
Lolidie Jeena Zubiri
13,238 PointsIntroducing Rewrite Rules Challenge 3 of 3
Help! I don't know what's wrong in my code: Finally, we need to write the second part of the rewrite rule. This is the location of the code that should be executed when someone requests a web address that matches the pattern in the first part of the rewrite rule. (Remember that we want the code in the all_flavors.php file in the root of our htdocs directory displayed when the pattern is matched.)
RewriteEngine On
RewriteRule ^flavors/$ http://localhost/flavors/all_flavors/all_flavors/
1 Answer
Randy Hoyt
Treehouse Guest TeacherIf you take a look back at the shirts listing page in the video (5:45), the rewrite rule there looks like this:
RewriteEngine On
RewriteRule ^shirts/$ /shirts/shirts.php
This means, "when someone visits http://localhost/shirts/, execute the code in the file called shirts.php in the shirts folder inside the htdocs directory.
In this code challenge, we want to execute the code in the all_flavors.php file in the htdocs directory.
Does that help?
Lolidie Jeena Zubiri
13,238 PointsLolidie Jeena Zubiri
13,238 PointsThank you Randy. Your answer helped me. :) But I'm still confused, how would I know when to shorten/crop the Rewrite rule?
I finished the challenge by typing: ^flavors/$ /all_flavors.php
Why is it different from ^shirts/$ /shirts/shirts.php, where /shirts is required before shirts/php?
Randy Hoyt
Treehouse Guest TeacherRandy Hoyt
Treehouse Guest TeacherLooking at just the second part of the rule ...
/shirts/shirts.php... the slash starts at the root of the website. In my code, there's a folder at the root of the website called /shirts/ with a file in it called shirts.php. In the code challenge, the all_flavors.php file is directly in the root of the website.
Does that help?
Lolidie Jeena Zubiri
13,238 PointsLolidie Jeena Zubiri
13,238 PointsYes. Thank you so much for explaining. :)