my query is about either creating a regex to capture:
- 0 or More Subcategories
- 0 or 1 Paging index
- 0 or 1 Product Id
This would be done easily by reading everything as a single parameter and this parameter passed to php, however it would imply tons of code and a performance hit whereas htaccess+regex will do this with a single line of code.
Example:
catalog/
Show all products starting from page 0
catalog/dolls/barbie/malibu/
display all malibu barbie dolls starting from page 0
catalog/dolls/gijoe/p_5/id_99
display product id_99. However the page and categories are maintained to be displayed as navigational links.
catalog/dolls/p_3
catalog/dolls/barbie/id_456
RewriteRule ^catalog/(([^/:*?"<>|\r\n]*/)*)(id-([0-9]{1,4}+))*$ catalog.php?category=$1&id=$3
Ive tried with a url like catalog/doll/barbie/id-1234/ like this; however capturing $1 would yield doll/barbie/id-1234/ and stuff like id-1234/id-345/id-145/ would be ‘valid’ returning 145 hence hurting seo placement with duplicate pages, this regex dont even deal with paging… I use RegexBuddy3 (very useful, a MUST buy) but apache+httacess don’t behave 100% the same when dealing with über long expressions.
The easiest would be to pass the id of both the category and the product in the URL
You can make the URL look like this
catalog/dolls-12/ – You are now looking in the catalogue at the category id 12
catalog/dolls/barbie/malibu-33/ – You are now looking in the catalogue at the category id 33
catalog/dolls/barbie/malibu-33/barbie-450 – You are now looking in the catalogue at the category id 33 and at the product 450
This should be all done with 3 rules in htaccess. If you receive a link that looks like
catalogue/(.*)-number/(.*)-number you are looking at a product inside a category.
catalogue/(.*)-number then you are looking at a category
catalogue/ – you are looking at the entire catalogue.
You do not need to capture everything, just the numbers, those will already tell you where you are.