Rewriteing partially

What i’m trying to do is take:
http://www.mysite.com/api/download?var1=moo&var2=quack

and turn it into:
http://www.mysite.com/api/index.php?action=download&var1=moo&var2=quack

There will be a few different words that go into the place ‘download’ occupies, though those are enumerated and few (5-6 of them). the variables are of variable count and size.

SL,

Was there a question in there?

Ya wanna know how, eh?
What have you tried?
Are you on an Apache server?
Which version?

Yeah, yeah, I’m violating my own rule not to provide free code (only to help members LEARN how to write … and, therefore, maintain … their own code):

RewriteEngine on
RewriteCond %{QUERY_STRING} ^var1=[^&]+&var2=[^&]+
RewriteRule ^api/download$ api/index.php?action=download [QSA,L]

There are nuances in there but I’ll let you finally ASK a question if you’re interested (including turning download into a short list OR making it completely variable).

Regards,

DK

Well the question was obviously ‘how, if possible’…
but anyway…

the idea is that i’m migrating from a system using ruby (where /api/download fires a script, and /api/check_email fires a different one in the same file)

so… the question is how to translate a URL in the format:
/api/{1}[?{2}={3}[&{2}={3}]]
into
/api/index.php?action={1}[&{2}={3}]

the possible values of {1} being: get_key,check_key,ensure_key,check_email,get_addons,trial_addon,download,report_errors
{2} and {3} are completely variable.
(Note: If it’s easier to make {1} completely variable, that’s fine, and i’ll handle it in the PHP code)

I havent actually tried anything; I havent done rewrites before; but since the ruby code will no longer be available, this will be a one-time thing.

Apache Version 2.2.3

SL,

Well, did you try using the code above?

For your list, replace download with (get_key|check_key|ensure_key|check_email|get_addons|trial_addon|download|report_errors) OR ([a-z_]+). Of course, the download in the redirection query string will be replaced by $1.

Having already given you the answer:

[rant #3][indent]My purpose for being here is to share knowledge, not to do free coding. I consider requests for free code to be from “script kiddies” and will not respond to them. Take the time and make an effort to learn and you’ll get all the assistance you need![/indent][/rant #3]

In other words, please take the time to learn something as mod_rewrite is a fantastic and very powerful tool. You appear to have the regex knowledge to limit the time you’ll spend and the benefits would be overwhelming.

Regards,

DK