My environment is Apache, DB is mySQL and language is PHP.
What I need is to create a middle layer which intercept the request and check the urls such as "http://www.something.com/apple/ipad-2-cases/" and then look up the db and where both apple and ipad-2-cases has a counter such as below:
Products Table
- p_id --> 1
- p_name --> "iPad"
- p_custom_url --> "ipad-2-cases"
Brands Table
- b_id --> 2
- b_name --> "Apple"
- b_custom_url --> "apple"
and convert the url into "http://www.something.com/products.php?b_id=2&p_id=1" from where I can grab b_id and p_id to bring out appropriate product info.
It basically quite looks like the way implemented in Joomla. You can define your own user-friendly url by typing an extra field otherwise it implements default setting anyway.
Since I am new to PHP, I don't quite know how to accomplish this. IN asp.net I've been using URL-Writer library which uses HttpHandlers and HttpModules to intercept the current request and make proper replacements.
Is there any library or something out there which can help me out on this one? Or do I need to use .htaccess (I know I need to turn on the mod_urlwrite on .htaccess)
Thanks a lot.
RewriteMapmay be your friend here - see e.g. this: stackoverflow.com/questions/5717796/…