views:

32

answers:

1

This drives me crazy, it should be easy but I can't...

I need to rewrite URLs like this ones:

www.domain.com/foo/bar/more/evenmore.htm
www.domain.com/foo/bar/more.htm
www.domain.com/foo/bar.htm
www.domain.com/foo.htm

into:

www.domain.com/?var1=foo&var2=bar&var3=more&var4=evenmore
www.domain.com/?var1=foo&var2=bar&var3=more
www.domain.com/?var1=foo&var2=bar
www.domain.com/?var1=foo

variable values may contain [a-z] [A-Z] [0-9] - _

+1  A: 

I don't think there's a single clean way to do it; I believe you need to use one rule per number of possible elements in the path. For example:

^([^\/]*)\/([^\/]*)\/([^\/]*)\/(.*).htm$ ?var1=$1&var2=$2&var3=$3&var4=$4 [L]
^([^\/]*)\/([^\/]*)\/(.*).htm$           ?var1=$1&var2=$2&var3=$3 [L]
^([^\/]*)\/(.*).htm$                     ?var1=$1&var2=$2 [L]
^([^\/]*).htm$                           ?var1=$1 [L]

You can add up to nine rules, because (AFAIK) mod_rewrite is limited to $1 through $9 as substitution parameters.

John Calsbeek
works fine, thanks! :)
Pedro Ladaria