mod_rewrite recipe for path to query string conversion...

mod_rewrite recipe for path to query string conversion...

am 09.06.2007 20:50:13 von contemptuous

Hi,

I have a url that accepts categories via a query string ala
http://host.doma.in/category.cfm?cat1=foo&cat2=bar&cat3=baz

now, i want to accept queries for this at a nice friendly clean url
like:

http://host.doma.in/category/foo/bar/baz

normally, i have no problem doing this with mod_rewrite, except that
in this case
i might have variable number of categories (1-20)

http://host.doma.in/category/foo/bar/baz/bat/bas/foo2/bar2/b az3/bat5/goo
or just

http://host.doma.in/vategory/foo/bar

any quick recipes for dealing with this ?

Re: mod_rewrite recipe for path to query string conversion...

am 11.06.2007 19:47:42 von Jim Hayter

contemptuous@gmail.com wrote:
> Hi,
>
> I have a url that accepts categories via a query string ala
> http://host.doma.in/category.cfm?cat1=foo&cat2=bar&cat3=baz
>
> now, i want to accept queries for this at a nice friendly clean url
> like:
>
> http://host.doma.in/category/foo/bar/baz
>
> normally, i have no problem doing this with mod_rewrite, except that
> in this case
> i might have variable number of categories (1-20)
>
> http://host.doma.in/category/foo/bar/baz/bat/bas/foo2/bar2/b az3/bat5/goo
> or just
>
> http://host.doma.in/vategory/foo/bar
>
> any quick recipes for dealing with this ?
>

Try:

RewriteRule
^/category/?([^/]*)/?([^/]*)/?([^/]*)/?([^/]*)/?([^/]*)/?([^ /]*)/?([^/]*)/?([^/]*)/?$
/category.cfm?cat1=$1&cat2=$2&cat3=$3&cat4=$4...

The above rule handles up to 8 (I arbitrarily stopped the rule)
arguments embedded in the URL. I know this will work up to 9. I'm not
sure it is valid beyond that as I don't know how the reference to the
parenthesized strings above 9 would be done.

Jim