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 trialLeigh Maher
21,830 PointsIs this a messy solution to get a clean url?
Is this typically how you wold resolve the issue of clean urls? Seems to me like we should be creating some kind of mod rewrite to handle this?
Creating folders and putting a single file into them just to gain a clean url seems like a convoluted and messy way of achieving this.
p.s. I don't know how to do mod rewrites. I just know of them.
3 Answers
Alexander Smith
2,769 PointsMod rewrites is the correct way and yes your way is messy.
Mod rewrites are basically regex(regular expressions) which teamtreehouse does have a couple courses on (oddly not for php though).
For regex you can try Regex The Hard Way it's made by the same person that did the ever popular python the hard way (and more now but not sure what the same of it is. Regex is pretty straight forward once you can wrap your head around it.
For setting up mod_rewrite something like this tutorial from digital ocean would probably be of more help.
Leigh Maher
21,830 PointsThanks for the resources, Alexander. In the next video he actually goes through rewrites. Although, he continues to use this folder method, which just seems wrong to me. Maybe in further videos, he'll offer a cleaner solution.
Alexander Smith
2,769 PointsI mean it depends sometimes you will want to break things down into folders but in my experience most of the files end users will access directly are normally kept in the root directory of the site. Then the content that is generated from is done using rewrites instead of index.php?a=141414 (you know what I mean :P).
Now something will still be done through folders. Like an Admin CP will probably use more than one php file so it would make sense to put in a different folder.
Leigh Maher
21,830 PointsYep, that makes sense. Thanks Alexander.