2010-03-14 18 views
5

Apache è il front-end della mia app Web, quindi uso mod_rewrite per inoltrare la richiesta a JBoss. Finora questo suona piuttosto standard, ma il problema che sto avendo è: se accedo l'applicazione direttamente attraverso JBoss @http://localhost:8080/app/page?raw=foo%26bar&page=1:Apache/mod_rewrite> Codifica Tomcat% 26 e "&"

request.getParameter("raw") = foo&bar 

Se accedo l'applicazione tramite Apache @http://localhost/foo%26bar&page=1

request.getParameter("raw") = foo 

Così da qualche parte lungo la strada, lo %26 viene perso e sostituito con uno & che riduce la variabile non elaborata.

Questa è la mia regola di riscrittura di Apache.

RewriteRule ^/(.*) \ 
    http://localhost:8080/app/home?raw=$1 [L,P] 

Il log di accesso Apache mostra: http://localhost/foo%26bar&page=1

e il registro di riscrittura mostra: http://localhost:8080/app/home?raw=foo&bar&page=1

Ma io voglio la richiesta di essere: http://localhost:8080/app/home?raw=foo%26bar&page=1

Sono abbastanza sicuro che questo si verifica anche con le barre / troppo per me questa è una sorta di problema di codifica. C'è un modo per proxy intatto l'URL? Non riesco a capire questo fuori.

EDIT:

La prima cosa che vorrei dire è grazie a Gumbo per avermi dato degli ottimi suggerimenti! Sulla base di questi suggerimenti, ho semplificato la configurazione di Apache a scopo di test.

Questo è ciò che sembra:

ServerRoot "C:/apps/xampplite/apache" 
Listen 80 

LoadModule rewrite_module modules/mod_rewrite.so 
LoadModule log_config_module modules/mod_log_config.so 

ServerAdmin [email protected] 
ServerName localhost:80 
DocumentRoot "C:/apps/xampplite/htdocs" 
ErrorLog "logs/error.log" 
LogLevel debug 
DefaultType text/plain 

<IfModule log_config_module> 
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined 
    LogFormat "%h %l %u %t \"%r\" %>s %b" common 

    <IfModule logio_module> 
     LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio 
    </IfModule> 
    CustomLog "logs/access.log" combined 
</IfModule> 

RewriteEngine On  
RewriteLog "C:/apps/xampplite/apache/logs/rewrite.log" 
RewriteLogLevel 9 
RewriteMap escape int:escape 
RewriteRule ^/(.*) http://localhost:8080/app/home?raw=${escape:$1} [L,P] 

qui sono i passi che ho preso: Avviare Apache, andare a

http://localhost/foo%26bar&page=1 

nel mio browser web, smettere di Apache.

voci di log di accesso: le voci di registro

::1 - - [15/Mar/2010:19:17:18 -0400] "GET /foo%26bar&page=1 HTTP/1.1" 403 224 "-" "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6" 

riscrittura: voci di registro

::1 - - [15/Mar/2010:19:17:18 --0400] [localhost/sid#54d160][rid#5e1360/initial] (2) init rewrite engine with requested uri /foo&bar&page=1 
::1 - - [15/Mar/2010:19:17:18 --0400] [localhost/sid#54d160][rid#5e1360/initial] (3) applying pattern '^/(.*)' to uri '/foo&bar&page=1' 
::1 - - [15/Mar/2010:19:17:18 --0400] [localhost/sid#54d160][rid#5e1360/initial] (5) map lookup OK: map=escape key=foo&bar&page=1 -> val=foo&bar&page=1 
::1 - - [15/Mar/2010:19:17:18 --0400] [localhost/sid#54d160][rid#5e1360/initial] (2) rewrite '/foo&bar&page=1' -> 'http://localhost:8080/app/home?raw=foo&bar&page=1' 
::1 - - [15/Mar/2010:19:17:18 --0400] [localhost/sid#54d160][rid#5e1360/initial] (3) split uri=http://localhost:8080/app/home?raw=foo&bar&page=1 -> uri=http://localhost:8080/app/home, args=raw=foo&bar&page=1 
::1 - - [15/Mar/2010:19:17:18 --0400] [localhost/sid#54d160][rid#5e1360/initial] (2) forcing proxy-throughput with http://localhost:8080/app/home 

errore:

[Mon Mar 15 19:16:56 2010] [notice] Apache/2.2.12 (Win32) configured -- resuming normal operations 
[Mon Mar 15 19:16:56 2010] [notice] Server built: Jul 22 2009 11:35:54 
[Mon Mar 15 19:16:56 2010] [notice] Parent: Created child process 2324 
[Mon Mar 15 19:16:56 2010] [debug] mpm_winnt.c(487): Parent: Sent the scoreboard to the child 
[Mon Mar 15 19:16:57 2010] [notice] Child 2324: Child process is running 
[Mon Mar 15 19:16:57 2010] [debug] mpm_winnt.c(408): Child 2324: Retrieved our scoreboard from the parent. 
[Mon Mar 15 19:16:57 2010] [info] Parent: Duplicating socket 148 and sending it to child process 2324 
[Mon Mar 15 19:16:57 2010] [info] Parent: Duplicating socket 140 and sending it to child process 2324 
[Mon Mar 15 19:16:57 2010] [debug] mpm_winnt.c(605): Parent: Sent 2 listeners to child 2324 
[Mon Mar 15 19:16:57 2010] [debug] mpm_winnt.c(564): Child 2324: retrieved 2 listeners from parent 
[Mon Mar 15 19:16:57 2010] [notice] Child 2324: Acquired the start mutex. 
[Mon Mar 15 19:16:57 2010] [notice] Child 2324: Starting 64 worker threads. 
[Mon Mar 15 19:16:57 2010] [notice] Child 2324: Starting thread to listen on port 80. 
[Mon Mar 15 19:16:57 2010] [notice] Child 2324: Starting thread to listen on port 80. 
[Mon Mar 15 19:17:18 2010] [error] [client ::1] attempt to make remote request from mod_rewrite without proxy enabled: proxy:http://localhost:8080/app/home 
[Mon Mar 15 19:17:52 2010] [notice] Parent: Received shutdown signal -- Shutting down the server. 
[Mon Mar 15 19:17:52 2010] [notice] Child 2324: Exit event signaled. Child process is ending. 
[Mon Mar 15 19:17:52 2010] [info] Child 2324: Accept thread exiting. 
[Mon Mar 15 19:17:53 2010] [notice] Child 2324: Released the start mutex 
[Mon Mar 15 19:17:53 2010] [info] Child 2324: Accept thread exiting. 
[Mon Mar 15 19:17:53 2010] [info] Child 2324: 64 threads blocked on the completion port 
[Mon Mar 15 19:17:54 2010] [notice] Child 2324: All worker threads have exited. 
[Mon Mar 15 19:17:54 2010] [notice] Child 2324: Child process is exiting 
[Mon Mar 15 19:17:54 2010] [notice] Parent: Child process exited successfully. 
[Mon Mar 15 19:17:54 2010] [info] removed PID file C:/apps/xampplite/apache/logs/httpd.pid (pid=1424) 

È interessante notare che la prima voce nel log di accesso mostra il% 26 ed è andato nella prima voce del registro di riscrittura.

Ancora perplesso da questo ...

risposta

1

provare con la NE flag per impedire la fuga di quel personaggio:

RewriteRule ^/(.*) http://localhost:8080/app/home?raw=$1 [NE,L,P] 

Edit Penso che ho avuto quel torto. Anziché impedire che il valore venga salvato, è necessario imporre l'escape. Provalo con la funzione di fuga interna:

RewriteMap escape int:escape 
RewriteRule ^/(.*) http://localhost:8080/app/home?raw=${escape:$1} [L,P] 
+0

ho provato: RewriteRule ^/(. *) \ http : // localhost: 8080/app/home? raw = $ 1 [NE, L, P] Non c'è fortuna, la voce del registro di riscrittura è la stessa di quella senza il flag NE. Forse la bandiera è nel posto sbagliato? – user293479

+0

Sembrava promettente ma ancora senza fortuna. Ho aumentato il livello di log in Apache/riscrittura e scoperto qualcosa ... La prima riga simile a questa: INIT riscrivere motore con richiesta URI/foo & Bar & page = 1 Questo non vuol dire che stiamo già lavorando con un stringa manipolata? Non dovrebbe ancora essere:/foo% 26bar & page = 1 a questo punto? ulteriormente nei log possiamo vedere la fuga: mappa di ricerca OK: map = sfuggire key = foo & bar & page = 1 -> val = foo & Bar & page = 1 , ma sembra che ci sia nulla da fare perché il% 26 era già convertito in &. – user293479

+0

@ user293479: usi altre regole? – Gumbo

1

questo dovrebbe funzionare:

RewriteRule ^/(.*) http://localhost:8080/app/home?raw=$1 [B,NE,L,P] 

come dovrebbe questo:

RewriteCond %{REQUEST_URI} ^/(.*) 
RewriteRule ^/(.*) http://localhost:8080/app/home?raw=%1 [L,P]