Jump to content

Recommended Posts

I am working on an e-commerce site. to There are two types of pages, products and categories. I can't work the best way to identify them in the htaccess.

example urls:

site.com/category/product

site.com/category/sub-category/product1

site.com/category/sub-category/sub-sub-category

 

 

There are essentially an unlimited level of sub-categories.

 

So I am guessing I need to explode the url

 

$url = (explode("/",$url);

So from there I will have an array of urls. I thought the best thing to do would take the last element in the array, and check to see if it is in the database for the products. But then what if the products and categories have the same same?

Any other ideas?

Either make all the products conform to a pattern:

site.com/category/p-productname

site.com/category/sub-category/p-name1

site.com/category/sub-category/sub-sub-category

 

or if you have a name that is ambiguous keep going up levels until you disambiguate:

So if you start with:

site.com/category/sub-category/product1 = site.com/cars/sports/ferrari

 

and ferrari is in both the product and category table, go up a level and see if the product ferrari is in the sports category - if it is great - if not you are in the subcategory ferrari.

Ok, I get it, this is not possible to determine, so I need to create validation so that the product and categories do not have the same urls. So if I do that, should I do the look up for the last array element, like I said at the start. Would that be the best way? Or is it going to slow down things.

I think it is possible to determine. Let me try to explain my example again:

 

Category Table:

id       Parent id     Cat name

1                            cars

2             1             sports

3              1            luxury

4              2            ferari

 

Products

prodid        cat      prod name

1                 4         ferari

2                 4         deluxe ferari

 

now, you ca get 4 kinds of urls:

1. site.com/cars/sports/ferari           // cat with name same as product

2. site.com/cars/sports/ferari/ferari //prod with name same as cat

3. site.com/cars/sports                    // cat name unique

4. site.com/cars/sports/ferari/deluxe ferari  //prod name unique

 

You look up the last part of the url  by prod name in case 3 you get no results for prod "sports" so you know the url ends in a category

Once you find the product record you look at the category column.

In case 1 you see cat id is 4 - read the category table and you see that the next level up is not ferari - so you are in the category ferari

In case 2 you see cat id is 4 - read the category table and the Cat name column == the name of cat 4 - so it is the ferari product

in case 4 you see cat id is 4 - read the category table and the Cat name column == the name of cat 4 - so it is the deluxe ferari product

Edited by davidannis
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.