Forum Moderators: phranque

Message Too Old, No Replies

'dynamic' rewriting

rewrite /filename/p1=v1/.../p20=v20 to filename.php?p1=v1&...&p20=v20

         

ArthurDent

10:30 am on Jun 17, 2006 (gmt 0)

10+ Year Member



Hi!

I'd like to dynamic rewrite a given url. example: /filename/p1=v1/p2=v2/.../p20=v20 (p=parameter, v=value)

mod_rewrite shall rewrite it to

filename.php?p1=v1&p2=v2...&p20=v20

But I don't know how many parameters there are. It may be 20 but could also be 2 or 100. So how can I create a 'dynamic' pattern matching and replacing for mod_rewrite?

hope you understand and can help!

cheers,
arthur :)

jdMorgan

3:54 pm on Jun 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A single and simple mod_rewrite rule can handle only 9 URL-path path or query-string variables. I'd suggest you simply rewrite *all* URLs with complex query strings to a script, and then let the script access the HTTP request headers, get the requested URL and query string data, and sort out all the query parameters.

Jim

ArthurDent

11:10 am on Jun 20, 2006 (gmt 0)

10+ Year Member



Thanks for your answer! Actually the server is going to handle lots of requests and I don't want to slow it just because of a rewrite map.

Isn't there a way, to simply replace EVERY / by a &? That would solve my problem.

Thanks and cheers

jdMorgan

3:23 pm on Jun 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> replace every "/" ...

Yes, you could do that by making the rewriterule recursive, but that is terribly inefficient.

If you want to try it anyway, see the [N] flag of RewriteRule, and heed the warnings about code position. You'll also need the [QSA] flag to retain query parameters created by previous rewrite passes.

[added]I was not referring to creating a separate script to be called by RewriteMap; I was suggesting that you rewrite all (appropriate) URL requests to your existing script(s), and then have that/those scripts get the parameters out of the originally-requested 'static' URL by accessing the server variable containing that requested URL. [/added]

Jim