Re: [OT] Rewrite arguments?
Hi there, Didn't see a reply to this yet... On Thu, 4 Jan 2001, Les Mikesell wrote: This may or may not be a mod_perl question: Probably not :) I want to change the way an existing request is handled and it can be done by making a proxy request to a different host but the argument list must be slightly different.It is something that a regexp substitution can handle and I'd prefer for the front-end server to do it via mod_rewrite but I can't see any way to change the existing arguments via RewriteRules. I don't exactly understand your problem, but from what I can see you should be able to do what you want with mod_rewrite if you just use a regexp which contains a question mark. Have I missed something? Does this extract from the docs help? -- One more note: You can even create URLs in the substitution string containing a query string part. Just use a question mark inside the substitution string to indicate that the following stuff should be re-injected into the QUERY_STRING. When you want to erase an existing query string, end the substitution string with just the question mark. Note: There is a special feature: When you prefix a substitution field with http://thishost[:thisport] then mod_rewrite automatically strips it out. This auto-reduction on implicit external redirect URLs is a useful and important feature when used in combination with a mapping-function which generates the hostname part. Have a look at the first example in the example section below to understand this. -- 73, Ged.
Re: [OT] Rewrite arguments?
- Original Message - From: "G.W. Haywood" [EMAIL PROTECTED] To: "Les Mikesell" [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Friday, January 05, 2001 1:44 PM Subject: Re: [OT] Rewrite arguments? On Thu, 4 Jan 2001, Les Mikesell wrote: This may or may not be a mod_perl question: Probably not :) I have a feeling it is going to end up being possible only with LWP... I want to change the way an existing request is handled and it can be done by making a proxy request to a different host but the argument list must be slightly different.It is something that a regexp substitution can handle and I'd prefer for the front-end server to do it via mod_rewrite but I can't see any way to change the existing arguments via RewriteRules. I don't exactly understand your problem, but from what I can see you should be able to do what you want with mod_rewrite if you just use a regexp which contains a question mark. Have I missed something? One of us is missing something. I hope it is me, but when I turn on rewrite logging, the input side contains only the location portion. The argument string has already been stripped. Apparently it is put back in place after the substition, since ^(.*)$ http://otherserver$1 [P] will send the same arguments on to the downstream host. Does this extract from the docs help? -- One more note: You can even create URLs in the substitution string containing a query string part. Just use a question mark inside the substitution string to indicate that the following stuff should be re-injected into the QUERY_STRING. When you want to erase an existing query string, end the substitution string with just the question mark. This allows adding additional arguments, or deleting them all. I want to change an existing one and add some more. Something like: /cgi-bin/prog?arg1=22arg2=24 should become: http://otherhost.domain/prog?newarg1=22arg2=24uname=mepwd=password Note: There is a special feature: When you prefix a substitution field with http://thishost[:thisport] then mod_rewrite automatically strips it out. This auto-reduction on implicit external redirect URLs is a useful and important feature when used in combination with a mapping-function which generates the hostname part. Have a look at the first example in the example section below to understand this. That won't affect this case. The hostname will be fixed and always require the proxy mode. Les Mikesell [EMAIL PROTECTED]
Re: [OT] Rewrite arguments?
"Les Mikesell" [EMAIL PROTECTED] wrote: I have a feeling it is going to end up being possible only with LWP... I don't exactly understand your problem, but from what I can see you should be able to do what you want with mod_rewrite if you just use a regexp which contains a question mark. Have I missed something? One of us is missing something. I hope it is me, but when I turn on rewrite logging, the input side contains only the location portion. The argument string has already been stripped. the query string is stripped from what the rewrite rule is matching, yes. but you can use a RewriteCond above the rule to test %{QUERY_STRING} against a regexp pattern, and store backreferences from it as %1, %2...etc. Does this extract from the docs help? -- One more note: You can even create URLs in the substitution string containing a query string part. Just use a question mark inside the substitution string to indicate that the following stuff should be re-injected into the QUERY_STRING. When you want to erase an existing query string, end the substitution string with just the question mark. This allows adding additional arguments, or deleting them all. I want to change an existing one and add some more. Something like: /cgi-bin/prog?arg1=22arg2=24 should become: http://otherhost.domain/prog?newarg1=22arg2=24uname=mepwd=password Also from the RTFM dept: 'qsappend|QSA' (query string append) This flag forces the rewriting engine to append a query string part in the substitution string to the existing one instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule. a possibly relevant example would be: # match and store the interesting arg values as backrefs RewriteCond %{QUERY_STRING} arg1=([0-9]+)arg2=([0-9]+) # build a new QS for the proxy url RewriteRule ^/cgi-bin/prog http://otherhost/prog?newarg1=%1arg2=%2uname=mepwd=password [R,L] (but without the linewrap, of course) in this example you dont need the qsappend flag because we reconstructed the entire query string. if you werent renaming agr1 to newarg1 (or if ther may have been other args you want to pass on) you could have just done: # just test for the presence of our args in the QS # and make the whole thing conditional on that RewriteCond %{QUERY_STRING} arg1=[0-9]+arg2=[0-9]+ #and rewite, injecting just the new args RewriteRule ^/cgi-bin/prog http://otherhost/prog?uname=mepwd=password [QSA,R,L] and the rw engine will add uname pwd to any existing querystring that was present hope this helps, -dave
Re: [OT] Rewrite arguments?
Would something like RewriteMap work? http://httpd.apache.org/docs/mod/mod_rewrite.html#RewriteMap At 09:43 PM 1/5/01 -0600, Les Mikesell wrote: - Original Message - From: "G.W. Haywood" [EMAIL PROTECTED] To: "Les Mikesell" [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Friday, January 05, 2001 1:44 PM Subject: Re: [OT] Rewrite arguments? On Thu, 4 Jan 2001, Les Mikesell wrote: This may or may not be a mod_perl question: Probably not :) I have a feeling it is going to end up being possible only with LWP... I want to change the way an existing request is handled and it can be done by making a proxy request to a different host but the argument list must be slightly different.It is something that a regexp substitution can handle and I'd prefer for the front-end server to do it via mod_rewrite but I can't see any way to change the existing arguments via RewriteRules. I don't exactly understand your problem, but from what I can see you should be able to do what you want with mod_rewrite if you just use a regexp which contains a question mark. Have I missed something? One of us is missing something. I hope it is me, but when I turn on rewrite logging, the input side contains only the location portion. The argument string has already been stripped. Apparently it is put back in place after the substition, since ^(.*)$ http://otherserver$1 [P] will send the same arguments on to the downstream host. Does this extract from the docs help? -- One more note: You can even create URLs in the substitution string containing a query string part. Just use a question mark inside the substitution string to indicate that the following stuff should be re-injected into the QUERY_STRING. When you want to erase an existing query string, end the substitution string with just the question mark. This allows adding additional arguments, or deleting them all. I want to change an existing one and add some more. Something like: /cgi-bin/prog?arg1=22arg2=24 should become: http://otherhost.domain/prog?newarg1=22arg2=24uname=mepwd=password Note: There is a special feature: When you prefix a substitution field with http://thishost[:thisport] then mod_rewrite automatically strips it out. This auto-reduction on implicit external redirect URLs is a useful and important feature when used in combination with a mapping-function which generates the hostname part. Have a look at the first example in the example section below to understand this. That won't affect this case. The hostname will be fixed and always require the proxy mode. Les Mikesell [EMAIL PROTECTED]
Re: [OT] Rewrite arguments?
- Original Message - From: "Dave Kaufman" [EMAIL PROTECTED] To: "Les Mikesell" [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Friday, January 05, 2001 11:09 PM Subject: Re: [OT] Rewrite arguments? One of us is missing something. I hope it is me, but when I turn on rewrite logging, the input side contains only the location portion. The argument string has already been stripped. the query string is stripped from what the rewrite rule is matching, yes. but you can use a RewriteCond above the rule to test %{QUERY_STRING} against a regexp pattern, and store backreferences from it as %1, %2...etc. That's it - thank you very much. I had seen how to match and reuse chunks in the RewriteCond, but somehow missed the ability to substitute them in the RewriteRule. I should have known it was too useful to have been left out. # match and store the interesting arg values as backrefs RewriteCond %{QUERY_STRING} arg1=([0-9]+)arg2=([0-9]+) # build a new QS for the proxy url RewriteRule ^/cgi-bin/prog http://otherhost/prog?newarg1=%1arg2=%2uname=mepwd=password [R,L] Since I only want to substitute one argument name without knowing much else I think this will work: RewriteCond %{QUERY_STRING} (.*)(arg1=)(.*) RewriteRule ^/cgi-bin/prog http://otherhost/prog?%1newarg1=%2uname=mepwd=password [P,L] (I want a proxy request to hide the password usage, not a client redirect but either could work) Les Mikesell [EMAIL PROTECTED]