Search and replace query string
Chuck Vose
vosechu at gmail.com
Mon Aug 6 23:12:11 MSD 2007
Since I didn't get a response I thought I would try a second
clarifying email and see if it makes more sense to the people that
know.
We're trying to take urls like this:
example.com/api?test1=test2&test3=test4
and turn them into urls like this:
example.com/api/test1/test2/test3/test4
This is easy if there are a fixed number of variables in the query
string but we don't have that. Sometimes we have /test1=test2 but
sometimes it's /test1=test2&test3=test4&test5=test6&test7=test8, etc.
I think the most we'll ever have is about 5 deep but I'm not sure.
So is there any way to have a search and replace regex? I couldn't
find any examples of s///g regex's in the documentation. Do I need to
get mod_perl involved or do we need to move to apache? Maybe it's just
time to reassess but this seems like an awesome solution if we can get
it rolling.
> Here's the code I've tried to create.
>
> if ($query_string ~ ^(s/(\?|&|=)(?:)/\//g)$) {
> set $new_url $1;
> rewrite ^(.*)$ $new_url.html break;
> }
Thanks again,
Chuck Vose
More information about the nginx
mailing list