Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite cgi redirect problem

         

jacquesv

8:00 am on Aug 23, 2004 (gmt 0)

10+ Year Member



i'm trying to redirect a post to an CGI....

/cgi/cgi.exe?isp=$1

to another java application....

/core/process?process=blah-blah-blah&isp-code=$1

$1 is the variable i want, posted to the CGI, posted to the java app.

jdMorgan

11:59 pm on Aug 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



jacques,

Welcome to WebmasterWorld!

Our policy, as noted in our charter [webmasterworld.com], is to help you get your code working, but we cannot write it for you. There are several examples of rewrites similar to what you need posted here in this forum. Please review the documentation using the links provided in our charter, try to write a rewriterule to do what you need, and post questions about your code if it does not work.

Jim

jacquesv

7:56 am on Aug 24, 2004 (gmt 0)

10+ Year Member



hi there...

i've been trying to write this rule for two days. i should posted my code. :)

the issue that i'm having is that i can't just relocate the query_string across because they differ from the CGI and the Java app. ie:

cgi = ispSelector?isp=blah

and the java =?process=enrollment&ispcrossover-enrollment.isp-code=blah

all i want to do is take the "blah" from the CGI post and slap it at the end of the ...isp-code=$1

i need to get this working asap... i'll pay money. :)

jdMorgan

12:58 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use

RewriteCond %{QUERY_STRING} isp=([^&]+)

to grab the "blah" value from the query string "isp" parameter and put it into back-reference variable %1.
Then reference %1 in the RewriteRule substitution to insert "blah" into the new query string.

Back-references %1 through %9 can be used to access RewriteCond subpattern matches in the same way that $1 through $9 are used to access RewriteRule subpattern matches. However, within a given RewriteRule, back-references will only be available to the last-matched RewriteCond, so be aware of this restriction if you use multiple RewriteConds for a rule.

Jim

jacquesv

1:23 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



hey there jdMorgan,

thanks very much for the tip!

this is my rule....

RewriteEngine on
RewriteLog /var/log/apache/redirect.log
RewriteLogLevel 1
RewriteCond %{QUERY_STRING} isp=([^&]+)
RewriteRule ^/cgi/server/ispSelector.exe$ [server...] [R]

if i try and access it just redirects me to [server...] and ommits the value of $1.

jacquesv

1:42 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



hi jim,

update: i see where i'm going wrong, i'm referencing $1 instead of %1. oops. :)

but now, i have another issue, the redirect is working but attaches %3f behind the variable... so...

......isp-code=blah%3f which does not work. how do i get rid of the %3f?

jdMorgan

1:56 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmm...

%3f is an ASCII question mark character. It is possible that the output of this rule is being processed by subsequent rules, one of which is attempting to append an addtional blank query string. Try using a [L] flag to tell mod_rewrite to quit after this rule is invoked:


RewriteRule ^/cgi/server/ispSelector.exe$ https://server/process?process=enrollment.isp-code=%1 [R,[b]L[/b]]

Jim

[edited] Fixed %1 in rule to reflect corrected code per post #6 [/edited]

[edited by: jdMorgan at 2:12 pm (utc) on Aug. 24, 2004]

jacquesv

2:05 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



Same thing... i'm googling for mod_rewrite and %3f and i see a few guys posting that they've got similar problems.

i'll scratch around and see what i can come up with. If you have anything else to suggest i'll watch for your post.

Otherwise thanks for helping out! :)

jacquesv

2:07 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



One more thing, this is the only mod_rewrite rule i have.