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 Enhancing a Simple PHP Application Cleaning URLs with Rewrite Rules Adding A Trailing Slash

Juliette Tworsey
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 Points

Adding a Trailing Slash with a RewriteRule

I'm I in the right ballpark? I'm stumped.

Thanks:-)

RewriteEngine  On   
RewriteRule ^flavors/$ /all_flavors.php
RewriteRule ^(/all_flavors.php/)$ /$1/ [R=301]
RewriteRule ^([/flavors]+)$ http://all_flavors.php/$flavors/ [R=301] 

2 Answers

Mohammed Khalil Ait Brahim
Mohammed Khalil Ait Brahim
9,539 Points

For the second rewrite rule I have a strange feeling about it. you store the value

$1 = /all_flavors.php/ 

and you do /$1/ which means //all_flavors.php// double slashes no ?

Juliette Tworsey
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 Points

This is what ended up working for me Mohammed:

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

Also, off topic, but I have just come across a pretty awesome Rewrite generator!

Maybe this could save some of us some headaches in the future:-)

https://donatstudios.com/RewriteRule_Generator

Mohammed Khalil Ait Brahim
Mohammed Khalil Ait Brahim
9,539 Points

Oh that looks like a very useful tool thanks for sharing Juliette :D