Forum Moderators: phranque

Message Too Old, No Replies

Mod_Rewrite query string

         

Proxis

11:37 am on May 25, 2006 (gmt 0)



Hello I've started to work with MOD_rewrite for our new site. Every link goes through a pl/sql procedure gateII for initialization and distribution. Sometimes I also call other functions like:

www.bla.com/nl/b2bmanagement/EXE/jedi.proxb2b.subscribe_newsletter?p_proc=1&p_email=&p_company_name=wcxvxc&P_LAST_NAME=cxwvx&P_FIRST_NAME=&p_lang=NL

Now my problem is that the gateII also takes the parameters from query_string. So I want to give query_string seperate to the function. I try to replace all '=' and '&' charcters of query_string. this works for links with a small amount of parameters:-(. Does somebody know a better way to convert characters.

My code


RewriteCond %{QUERY_STRING} (.*)=(.*)
RewriteRule (.*) - [env=QRY_STR:%1:%2]
#
RewriteCond %{QUERY_STRING} (.*)=(.*)&(.*)=(.*)
RewriteRule (.*) - [env=QRY_STR:%1:%2¦%3:%4]
#
RewriteCond %{QUERY_STRING} (.*)=(.*)&(.*)=(.*)&(.*)=(.*)
RewriteRule (.*) - [env=QRY_STR:%1:%2¦%3:%4¦%5:%6]
#
RewriteCond %{QUERY_STRING} (.*)=(.*)&(.*)=(.*)&(.*)=(.*)&(.*)=(.*)
RewriteRule (.*) - [env=QRY_STR:%1:%2¦%3:%4¦%5:%6¦%7:%8]
#
RewriteCond %{QUERY_STRING} (.*)=(.*)&(.*)=(.*)&(.*)=(.*)&(.*)=(.*)&(.*)=(.*)
RewriteRule (.*) - [env=QRY_STR:%1:%2¦%3:%4¦%5:%6¦%7:%8¦%9:%10]
#
RewriteCond %{QUERY_STRING} (.*)=(.*)&(.*)=(.*)&(.*)=(.*)&(.*)=(.*)&(.*)=(.*)&(.*)=(.*)
RewriteRule (.*) - [env=QRY_STR:%1:%2¦%3:%4¦%5:%6¦%7:%8¦%9:%10¦%11:%12]
#
RewriteRule ^/(NL¦FR¦EN)/(.+)/$ /gate/JEDI.gate.gateII?lang=$1&p2=$2&loglevel=%{ENV:LOGLEVEL}&page=%{ENV:PAGE}&query_string=%{ENV:QRY_STR} [last,nocase,proxy]

In the end I must become a link like this:

wwww.bla.com/nl/b2bmanagement/EXE/jedi.proxb2b.subscribe_newsletter?p_proc:1¦p_email:¦p_company_name:wcxvxc¦P_LAST_NAME:cxwvx¦P_FIRST_NAME:¦p_lang:NL

But after the rewrite I get the link :
wwww.bla.com/nl/b2bmanagement/EXE/jedi.proxb2b.subscribe_newsletter?p_proc:1¦p_email:¦p_company_name:wcxvxc¦P_LAST_NAME:cxwvx¦P_FIRST_NAME:p_proc0¦p_proc1:p_proc2

Is it not possible to use %10,%11 or higher in the rewriterule?

jdMorgan

1:13 pm on May 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is a nasty problem. Mod_rewrite is limited to 9 back-references for each of RewriteCond (%1-%9) and RewriteRule ($1-$9).

The two most-attractive suggestions I can think of are:

1) Use RewriteMap to call a script to do the mass character substitution. Changing the characters would be fast and easy in PERL, for example. RewriteMaps must be defined in the server-config context, but may be used in any context.

2) Change your existing script to accept the 'wrong' characters and change them to the right ones internally. You could change the scripts themselves, or add a 'shell' around them to do the character substition and then call the correct script.

Note that


RewriteCond %{QUERY_STRING} (.*)=(.*)
RewriteRule (.*) - [env=QRY_STR:%1:%2]

is more usually written as

RewriteCond %{QUERY_STRING} ([^=]*)=(.*)
RewriteRule (.*) $1?%1:%2

Jim