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 trialPetrus Chan
4,848 PointsRewrite Rules - Extremely Advanced Question
If I wanted to append a SKU to my URL instead of the id, how would I be able to do so? The SKU would be like CROS-EN111. I know this is probably the most difficult part of this and I knew it would be but I thought there could be a way.
Any help would be appreciated!
Thanks! Petrus
4 Answers
Stephen Van Delinder
21,457 PointsHey Petrus,
I'm not sure I understand exactly what you are asking. You can add whatever you want to a URL with GET parameters. And you could get fancier with PHP's parse_url function...
But that might be overkill, have you considered using a data attribute?
<a href = "#" data-sku="CROS-EN111">item</a>
Petrus Chan
4,848 PointsHi Stephen,
The reason why I want to have the SKU display up is the fact that my database is extremely huge and has all the information and having the SKU in the URL would definitely make it easier to view and understand. The SKU is already in the database in it's own column. So in other words, whenever someone clicks on a shirt they will get the SKU that is retrieved from the database according to that shirt. I definitely could echo the SKU from the database in the data-attribute... good idea!
If I were to use the data-attribute, how would I be able to get it into the URL? The hardest part is modifying the htaccess file to allow to display numbers, letters and hyphens.
Thanks! Petrus
Stephen Van Delinder
21,457 PointsPetrus,
Thanks for clarifying that. I'm not sure what technology stack you are working with, but I will assume you're using a LAMP stack with a SQL server and you need a PHP app to pull database info based on parameters you append to the URL. There is a really good course on how to do that over here.
Good Luck!
Petrus Chan
4,848 PointsHi Stephen,
Thank you. I already finished that course previously and was working on the Enhancing the PHP application one. I was trying to enhance the Rewriting Rules for cleaner URLs, hence my problem. I've already pulled that data, now it's just trying to connect it to the htaccess and making a rewrite rule for it. I think I found a google source online:
https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/
Petrus