Apache Server configuration support - mod_rewrite recipe for path to query string conversion...

This is Interesting: Free IT Magazines  
Home > Archive > Apache Server configuration support > June 2007 > mod_rewrite recipe for path to query string conversion...





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author mod_rewrite recipe for path to query string conversion...
contemptuous@gmail.com

2007-06-09, 7:19 pm

Hi,

I have a url that accepts categories via a query string ala
http://host.doma.in/category.cfm?ca...t2=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/ba...2/baz3/bat5/goo
or just

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

any quick recipes for dealing with this ?

Jim Hayter

2007-06-11, 1:25 pm

contemptuous@gmail.com wrote:
> Hi,
>
> I have a url that accepts categories via a query string ala
> http://host.doma.in/category.cfm?ca...t2=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/ba...2/baz3/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
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com