0

Using RewriteMap in Apache 2.4 for some variable conversion referring this. Everything seems fine. Able to test the external program alone and it gives the expected output.

As per the link, the map key has to be terminated with new line. I do accept this as I am giving an 'enter' when testing manually.

So, now the question is how to send that new line to the external program from httpd.

My code is : RewriteRule .* - [E=USER_NEW:${MapTest:%{ENV:USER_TEST}}]

Anitha.R
  • 101
  • 2
  • Are you having a problem in testing? "how to send that new line to the external program" - You shouldn't need to do this in the call to the rewrite map. Apache itself should append the newline when calling the external program? So, your external program should expect this. Your program then needs to append a newline to the output (and Apache strips this before passing the value back to mod_rewrite). – MrWhite Apr 22 '19 at 15:27
  • Thank you. But my map is not returning the value. Not only that i have printed the received key inside the program. That is not getting printed. So I suspect this new line character. Is there any way to debug this – Anitha.R Apr 22 '19 at 19:20
  • Are you sure your external program is even being called? What did you mean by "Everything seems fine."? Have you defined the `RewriteMap` in the server config or virtualhost context? Restarted Apache etc.? Confirmed that your external program is being called? – MrWhite Apr 22 '19 at 21:21
  • 1. Tested the external program separately and working fine.. 2. Defined the RewriteMap in virtualhost context. 3. Restarted apache. 4. Found a line like this in the log. ` map lookup OK: map=MapTest key=Anitha.R -> val= `. But the print statements inside the program are not getting printed. So not sure whether the program gets called. – Anitha.R Apr 23 '19 at 06:39
  • "But the print statements inside the program are not getting printed." - You mean it's not getting returned to Apache? What language are you using? Presumably you are sending to STDOUT? FWIW, the tutorial article you linked to does not append a newline in the call to the rewrite map. – MrWhite Apr 23 '19 at 08:51
  • I am using Java. The STDERR will be sent to apache error.log as per the tutorial. But that is not coming.So I can assume here that the program is not getting called. But the log has `map lookup OK: map=MapTest key=Anitha.R -> val=`. So this tried calling the map. Then why the value is not getting returned. Reg Newline, I am not sending a newline along with the input. As you can see, in the log, it specifies the key value correctly. Note: I have tested that java program and it is working fine. – Anitha.R Apr 23 '19 at 09:15
  • I have debugged further and found that the input key is not passing into the program. Though the value is printed as key for map in the log, the print inside the program prints empty string. I am passing the value to the map as below : `RewriteRule .* - [E=USER_NEW:${MapTest:%{ENV:USER_TEST}}]` – Anitha.R Apr 23 '19 at 11:47

0 Answers0