Apache是我的web應用程序的前端,然後我使用mod_rewrite將請求代理到JBoss。到目前爲止,這聽起來很標準,但我遇到的問題是:如果我直接通過JBoss的訪問應用@http://localhost:8080/app/page?raw=foo%26bar&page=1
:Apache/mod_rewrite> Tomcat編碼%26和「&」
request.getParameter("raw") = foo&bar
如果我通過Apache訪問的應用程序@http://localhost/foo%26bar&page=1
request.getParameter("raw") = foo
所以在某個地方,%26
丟失,並被替換爲&
,這會切斷原始變量。
這是我的Apache重寫規則。
RewriteRule ^/(.*) \
http://localhost:8080/app/home?raw=$1 [L,P]
Apache的訪問日誌顯示:http://localhost/foo%26bar&page=1
而重寫日誌顯示:http://localhost:8080/app/home?raw=foo&bar&page=1
但我想請求是:http://localhost:8080/app/home?raw=foo%26bar&page=1
我敢肯定,這也發生斜線/
太對我來說這是一些編碼問題。有沒有辦法代理URL未觸動?似乎無法找出這一個。
編輯:
我想說的是第一件事,感謝你對濃湯給我一些很好的建議!基於這些建議,我簡化了我的Apache配置以用於測試目的。
這是什麼樣子:
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]
下面是我所採取的步驟:啓動Apache,去
http://localhost/foo%26bar&page=1
在我的網頁瀏覽器,停止Apache。
訪問日誌條目:
::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"
重寫日誌條目:
::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
錯誤日誌條目:
[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)
有趣的是在訪問日誌中的第一個條目顯示了%26並且它在重寫日誌的第一個條目中消失了。
仍然不解這個...
我想: 的RewriteRule^/(。*)\ HTTP :// localhost:8080/app/home?raw = $ 1 [NE,L,P] 不幸的是,重寫日誌條目與沒有NE標誌的條目相同。 也許國旗在錯誤的地方? – user293479 2010-03-14 20:06:36
看起來很有前途,但仍然沒有運氣。我的Apache /重寫增加了日誌級別,並發現了一些... 的第一行是這樣的: 的init重寫引擎與請求的URI/foo的酒吧和頁面= 1 這是否意味着我們已經與工作操縱的字符串?它不應該仍然是:/ foo%26bar&page = 1在這一點上? 進一步在日誌中我們可以看到轉義: 地圖查找OK:地圖=退出鍵= foo的酒吧和頁面= 1 - > VAL = foo的酒吧和頁面= 1 但似乎無關,因爲在%26已經轉換爲&。 – user293479 2010-03-14 23:42:30
@ user293479:您是否使用其他規則? – Gumbo 2010-03-15 07:04:17