views:

115

answers:

2

Regular expressions have always been my pet peeves. Every time I think that I finally got it I have a new problem !

I want to catch url like this :

http://www.mydomain.com/boutique/blabla-1/bla-bla2/99/104
http://www.mydomain.com/boutique/blabla1/99

and eventually :

http://www.mydomain.com/boutique/blabla-1/bla-bla2/product1/99/104/55/

after a lot of tries and errors I came up with this which seems to work with http://www.gskinner.com/RegExr/ but not in apache

^.*/boutique/([a-zA-Z-]*)(/?[a-zA-Z-]*)/?([0-9]*)/?([0-9]*)/?$   boutique.php?c1=$3&c2=$4

(I was only working with the first two url so far)

MY apache rewrite log debug files are helpless :

pass through /Users/iko/Sites/mysite/boutique.php

I'm only interrested in getting the ids. Any help we'll be welcomed !

Thank you.

A: 
RewriteRule ^boutique/(?:[a-zA-Z][\w-]*/){1,3}/(\d+)(?:/(\d+)(?:/(\d+))?)?/?$ boutique.php?c1=$1&c2=$2&c3=$3
Qtax
A: 

I personally like to write a rule for each type as I find it clearer to read (especially if htaccess is a bugbear of yours)

i.e.

### Rewrite rule for /boutique/blabla-1/bla-bla2/99/104
RewriteRule ^boutique/([a-z0-9-]+)/([a-z0-9-]+)/([0-9]+)/([0-9]+) boutique.php?c1=$3&c2=$4

To explain the different bits ([a-z0-9-]+) is basically all lowercase letters, numbers and hyphens. Similarily ([0-9]+) is just for numbers and hyphens

Hope this helps

Chris
thank you. in my case, as the number of parameters is fluid (between 1 and 3) I had to mark the slashes as optionnal
Cool - so you have it all working now?
Chris