I've seen a lot of discussion on URL Routing, and LOTS of great suggestions... but in the real world, one thing I haven't seen discussed are:
- Creating Friendly URLs with Spaces and illegal characters
- Querying the DB
Say you're building a Medical site, which has Articles with a Category and optional Subcategory. (1 to many). ( Could've used any example, but the medical field has lots of long words)
Example Categories/Sub/Article Structure:
- Your General Health (Category)
- Natural Health (Subcategory)
- Your body's immune system and why it needs help. (Article)
- Are plants and herbs really the solution?
- Should I eat fortified foods?
- Homeopathic Medicine
- What's homeopathic medicine?
- Healthy Eating
- Should you drink 10 cups of coffee per day?
- Are Organic Vegetables worth it?
- Is Burger King® evil?
- Is "French café" or American coffee healthier?
- Natural Health (Subcategory)
- Diseases & Conditions (Category)
- Auto-Immune Disorders (Subcategory)
- The #1 killer of people is some disease
- How to get help
- Genetic Conditions
- Preventing Spina Bifida before pregnancy.
- Are you predisposed to live a long time?
- Auto-Immune Disorders (Subcategory)
- Dr. FooBar's personal suggestions (Category)
- My thoughts on Herbal medicine & natural remedies (Article - no subcategory)
- Why should you care about your health?
- It IS possible to eat right and have a good diet.
- Has bloodless surgery come of age?
In a structure like this, you're going to have some LOOONG URLs if you go: /{Category}/{subcategory}/{Article Title}
In addition, there are numerous illegal characters, like # ! ? ' é " etc.
SO, the QUESTION(S) ARE:
- How would you handle illegal characters and Spaces? (Pros and Cons?)
- Would you handle getting this from the Database
- In other words, would you trust the DB to find the Item, passing the title, or pull all the titles and find the key in code to get the key to pass to the Database (two calls to the database)?
note: I always see nice pretty examples like /products/beverages/Short-Product-Name/ how about handling some ugly examples ^_^