Forum Moderators: phranque

Message Too Old, No Replies

Problem with RequestHeader and RewriteCond

         

kalibo1

6:19 pm on Nov 9, 2010 (gmt 0)

10+ Year Member



Hi all,

I want rerewrite 2 urls like this

http://mysite/start.jsp?id1=val1&id2=val2&id3=val3 ====> [mysite...]
with set Header (or RequestHeader) id1 and val1


http://mysite/start.jsp?id1=val1 ======> [mysite...] with set Header (or RequestHeader) id1 and val1


I can do the rewrite with this code

RewriteCond %{QUERY_STRING} ^id1=([^/]+)&id2=([^/]+)&id3=([^/]+)$
RewriteRule start\.jsp /start.jsp?id2=%2&id3=%3 [L,R=301] [E=foo:%1]

RewriteCond %{QUERY_STRING} ^id1=([^/]+)$
RewriteRule start\.jsp /start.jsp? [L,R=301] [E=foo:%1]

RequestHeader set id1 %{foo}e


But my problem is that I can't have the value in header %foo=val1

I need help please, thx

sublime1

2:31 am on Nov 13, 2010 (gmt 0)

10+ Year Member



Would it work to have [E=$1:%1]?

kalibo1

6:21 am on Nov 14, 2010 (gmt 0)

10+ Year Member



Like this ?

RewriteCond %{QUERY_STRING} ^id1=([^/]+)&id2=([^/]+)&id3=([^/]+)$
RewriteRule start\.jsp /start.jsp?id2=%2&id3=%3 [L,R=301] [E=$1:%1]

RewriteCond %{QUERY_STRING} ^id1=([^/]+)$
RewriteRule start\.jsp /start.jsp? [L,R=301] [E=$1:%1]

RequestHeader set id1 %{$1}e


it doesn't work :-(.

jdMorgan

11:26 pm on Nov 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



HOW does in not work? Please be specific about how you test, what results you get, and how those results differ from what you need. Otherwise, we have to guess at both the problem and the possible solution...

Jim

kalibo1

5:38 pm on Nov 18, 2010 (gmt 0)

10+ Year Member



I change the subject like this

[mysite...] -> [mysite...]
[mysite...] -> [mysite...]

if I do:
RewriteRule ^/id1/([^/]+)/(.*) /$2 [E=foo:$1,R]
RequestHeader add "id1" "%{foo}e"

Result : I have the right URL : [mysite...] but my header is not set , so my application doesn't work.

if I do:
RewriteRule ^/id1/([^/]+)/(.*) /$2 [E=foo:$1,P]
RequestHeader add "id1" "%{foo}e"

Rusult : strange :-( : I have the wrongr URL : [mysite...] but my header is set , so my application work.

I think, the problem is about a flag [R]. I leave my variable when I use this ....
Can someone help me .... thinx

jdMorgan

2:59 am on Nov 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd suggest:

RewriteRule ^/id1/([^/]+)/(.*)$ /$2 [E=foo:$1,L]
RequestHeader set id1: "%{foo}e"

however, this pre-supposes that mod_headers is executed after mod_rewrite, which may or may not be the case. If not, then you will need some other way to pass the "foo" value to your app, such as putting it into a query string and GETting it from there inside your application script.

Also note that most scripting languages have a variable containing the originally-requested URL-path, and can also use regular expressions. So it may not be necessary for your mod_rewrite code to pass the "foo" value at all, it may only need to invoke your app, and you app can read the requested URL directly to get the "foo" value.

Jim