Mod Rewrite Clean Urls Help Understanding
Posted 20 October 2006 - 02:43 PM
The book I am reading structures most all database with a primary key auto increment.
Suppose I have product an online store with product categories. Then the url for the page becomes something like:
<a href=\"seestore.php?cat_id=cat_id \">$cat_title</a>
In browser this becomes http://mysite.com/se...re.php?cat_id=1 (or 2,3,4 etc..)
My understanding is that I can use mod rewrite to make the url like this:
RewriteRule ^seestore/([0-9][0-9])/$ seestore.php?cat_id=$1
My questions lies in how do I get the number out of the url? For seo I would much rather have the category name be presented in the url.
For instance. http://mysite.com/seestore/hats/.
I am assuming that an easy way to do this would be to structure my database with the actual category names as the category id, but is this the best and only way to accomplish this?
You assistance with helping me understand this concept is much appreciated.
Posted 20 October 2006 - 05:07 PM
What I suggest is that you write different rule for each category -
RewriteRule ^seestore/hats/$ seestore.php?cat_id=1 RewriteRule ^seestore/shoes/$ seestore.php?cat_id=2
Technical Forum - http://www.enterpriseplatform.net/
Posted 20 October 2006 - 06:14 PM
RewriteEngine on RewriteRule ab(.*) /handler.php$1 [PT]
handler.php is essentially turned into the entry point for the site and allows for urls such as:
handler.php parses the URL into a series of parameters that the pages can ask for and make decisions on.
The nice thing to this approach is that it only requires a single rewrite rule for the entire site.
The thing I don't like about how it was implemented is that it forces the parameters in the URL to appear in a specific order. For example, for the shopping page it has to be: shopping/param1/param2/param3
So let's say that only param2 and param3 are set, I still have to put a placeholder for param1:
I would much rather prefer a mechanism where the url parameters can appear in any order and the next site I design will definately have this capability.
(EDIT) I know this doesn't answer your question, but I brought it up as something to take into consideration for your site.
Posted 20 October 2006 - 09:10 PM
Category_id Key Field Auto Increment
Product_id Key Field Auto Increment
If I am understanding correctly I would have to have a mod rewrite rule for each category and each product page.
So a product page may look like this:
RewriteRule ^seestore/hats/angels-baseball-hat$ seestore.php?cat_id=1&prodID=53
Is this correct?
Also, if I have a section of the site where users add a profile is there a more dynamic way to rewrite the url since I will not have a id upfront?
For instance think of a forum. Each post has a post id and post title. Essentially, I would want to rewrite a post id with the title of the post such as below:
No Mod rewrite: http://www.mysite.co..._id=1&postID=35
After Mod Rewrite: http://www.mysite.co...hit-a-baseball/
The “how to hit a baseball” is the post topic.
DO you have any suggestions for this?
Thank you very much for your help.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users