Hello all,
First post, but I'll try not to annoy you too much. I'm currently trying to write out a nice regex for Apache's ReWrite engine so that I can use search engine friendly (SEF) URLs. The problem I'm coming across is that optional parameters (such as language) are pulling in an 'undefined' value.
Here's and example:
EXAMPLE: en/bestbuy/section-5/category-2/HP-Pavilion-a1022n
All parameters EXCEPT the site-name are optional. This is because we'll assume English is the default language if none is provided, and of course if they're at the front page there will be no section, category or product identified. Note also that the language variable will always be 2 characters, no less, no more, and only a-z.
For ReWrite purposes I need to capture the language (en), site name (bestbuy), section ID (5), category ID (2), and entire product ID (HP-Pavilion-a1022n) into the $1/$2/etc variables so I can place them in the appropriate place for the new URL.
ATTEMPTS:
Language/Site only:
^([en]{2}|[sp]{2})?/?(\w*)$
Problem: Left $1 as undefined if en/sp was not present, otherwise it worked fine. This was alright at the time because if the variable is blank/undefined we can assume the default of English, but I'm not one to leave something working 95% correct.
Entire URL string:
^([en]{2}|[sp]{2})?/?(\w*)/?section-(\d*)/?category-(\d*)/?(.*)$
Problem: As you can see I was getting really frustrated and trying out really stupid crap. Works fine if all variables are in the URL string, but take out product and category and it died completely (wouldn't even pull in an 'undefined').
Any help would be VERY greatly appreciated.
- Matt