2010-03-14 4 views
5

Apache est le frontal de mon application Web, puis j'utilise mod_rewrite pour transmettre par proxy la requête à JBoss. Jusqu'à présent, cela semble assez standard, mais le problème que j'ai est: si j'accéder à l'application directement via jboss @http://localhost:8080/app/page?raw=foo%26bar&page=1:Apache/mod_rewrite> Codage Tomcat% 26 et "&"

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

Si j'accéder à l'application via Apache @http://localhost/foo%26bar&page=1

request.getParameter("raw") = foo 

Alors quelque part le long du chemin, le %26 est perdu et remplacé par un & qui coupe la variable brute.

Ceci est ma règle de réécriture Apache.

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

Le journal d'accès Apache indique: http://localhost/foo%26bar&page=1

Et le journal de réécriture montre: http://localhost:8080/app/home?raw=foo&bar&page=1

Mais je veux la demande soit: http://localhost:8080/app/home?raw=foo%26bar&page=1

Je suis assez sûr que cela se produit aussi avec des barres obliques / aussi pour moi c'est une sorte de problème d'encodage. Existe-t-il un moyen de proxy l'URL intacte? Je n'arrive pas à comprendre ça.

EDIT:

première chose que je voudrais dire est merci à Gumbo pour me donner de très bonnes suggestions! Sur la base de ces suggestions, j'ai simplifié ma configuration Apache à des fins de test.

Voici ce qu'il ressemble à:

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] 

Voici les étapes de mon travail: Apache Démarrer, allez à

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

dans mon navigateur web, arrêtez Apache.

entrées du journal d'accès:

::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" 

Réécrire entrées du journal:

::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 

erreur entrées du journal:

[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) 

Il est intéressant de la première entrée dans le journal d'accès montre le% 26 et il est parti dans la première entrée du journal de réécriture.

Toujours intrigué par celui-ci ...

Répondre

1

Essayez avec le NE flag pour empêcher échapper de ce caractère:

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

Modifier Je pense que je suis trompé. Plutôt que d'empêcher l'échappement de la valeur, vous devez forcer l'échappement. Essayez avec la fonction d'échappement interne:

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

J'ai essayé: RewriteRule ^/(. *) \ http : // localhost: 8080/app/home? raw = $ 1 [NE, L, P] Pas de chance, l'entrée du journal de réécriture est la même que sans le flag NE. Peut-être que le drapeau est au mauvais endroit? – user293479

+0

Cela semblait prometteur mais toujours pas de chance. J'ai augmenté le niveau de journalisation Apache/réécriture et découvert quelque chose ... La première ligne ressemble à ceci: init récrire moteur avec uri demandé/foo & Bar & page = 1 ce que cela ne signifie pas que nous travaillons déjà avec chaîne manipulée? Ne devrait-il pas encore être:/foo% 26bar & page = 1 à ce stade? De plus dans les journaux, nous pouvons voir le Escaping: carte recherche OK: map = s'échapper key = foo & bar & page = 1 -> val = foo & Bar & page = 1 , mais il semble y avoir rien à faire parce que le% 26 a déjà été converti en &. – user293479

+0

@ user293479: Utilisez-vous d'autres règles? – Gumbo

1

Cela devrait fonctionner:

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

Comme devrait ceci:

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