Bug 63866 - Rewrite rule for root URL path (/) matches and proxies request, but END flag is ignored and mod_dir issues sub-requests for index files
Summary: Rewrite rule for root URL path (/) matches and proxies request, but END flag ...
Status: NEW
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_rewrite (show other bugs)
Version: 2.4.41
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-18 21:32 UTC by Angelov
Modified: 2019-10-20 12:52 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Angelov 2019-10-18 21:32:24 UTC
Apache 2.4.41 on Ubuntu 16.04.5 LTS.

From what I gather from the docs, the use of the END flag should prevent sub requests but it does not - at least not when used in conjunction with the P flag. 

It seems that the issue only happens when requesting existing directories (/, /existing_dir, /dir/existing_sub_dir), it does not happen for file requests.

As a workaround, the undesired behaviour can be fixed by disabling the DirectoryIndex.

Here is the rewrite rule:

RewriteRule (.*) http://127.0.0.1:3000/test?q=$1 [P,END]

Here is the debug (trace5) log sample:

[Fri Oct 18 20:30:16.179651 2019] [rewrite:trace3] [pid 17308:tid 140453997967104] mod_rewrite.c(483): [client 10.20.0.40:62131] 10.20.0.40 - - [test1.local/sid#7fbe14d530b8][rid#7fbdf80930a0/initial] [perdir /var/www/html/test1/website/public/] strip per-dir prefix: /var/www/html/test1/website/public/ ->
[Fri Oct 18 20:30:16.179688 2019] [rewrite:trace3] [pid 17308:tid 140453997967104] mod_rewrite.c(483): [client 10.20.0.40:62131] 10.20.0.40 - - [test1.local/sid#7fbe14d530b8][rid#7fbdf80930a0/initial] [perdir /var/www/html/test1/website/public/] applying pattern '(.*)' to uri ''
[Fri Oct 18 20:30:16.179694 2019] [rewrite:trace2] [pid 17308:tid 140453997967104] mod_rewrite.c(483): [client 10.20.0.40:62131] 10.20.0.40 - - [test1.local/sid#7fbe14d530b8][rid#7fbdf80930a0/initial] [perdir /var/www/html/test1/website/public/] rewrite '' -> 'http://127.0.0.1:3000/test?q='
[Fri Oct 18 20:30:16.179699 2019] [rewrite:trace3] [pid 17308:tid 140453997967104] mod_rewrite.c(483): [client 10.20.0.40:62131] 10.20.0.40 - - [test1.local/sid#7fbe14d530b8][rid#7fbdf80930a0/initial] split uri=http://127.0.0.1:3000/test?q= -> uri=http://127.0.0.1:3000/test, args=q=
[Fri Oct 18 20:30:16.179703 2019] [rewrite:trace2] [pid 17308:tid 140453997967104] mod_rewrite.c(483): [client 10.20.0.40:62131] 10.20.0.40 - - [test1.local/sid#7fbe14d530b8][rid#7fbdf80930a0/initial] [perdir /var/www/html/test1/website/public/] escaped URI in per-dir context for proxy, http://127.0.0.1:3000/test -> http://127.0.0.1:3000/test
[Fri Oct 18 20:30:16.179706 2019] [rewrite:trace2] [pid 17308:tid 140453997967104] mod_rewrite.c(483): [client 10.20.0.40:62131] 10.20.0.40 - - [test1.local/sid#7fbe14d530b8][rid#7fbdf80930a0/initial] [perdir /var/www/html/test1/website/public/] forcing proxy-throughput with http://127.0.0.1:3000/test
[Fri Oct 18 20:30:16.179710 2019] [rewrite:trace1] [pid 17308:tid 140453997967104] mod_rewrite.c(483): [client 10.20.0.40:62131] 10.20.0.40 - - [test1.local/sid#7fbe14d530b8][rid#7fbdf80930a0/initial] [perdir /var/www/html/test1/website/public/] go-ahead with proxy request proxy:http://127.0.0.1:3000/test?q= [OK]
[Fri Oct 18 20:30:16.179756 2019] [rewrite:trace3] [pid 17308:tid 140453997967104] mod_rewrite.c(483): [client 10.20.0.40:62131] 10.20.0.40 - - [test1.local/sid#7fbe14d530b8][rid#7fbdf80710a0/subreq] [perdir /var/www/html/test1/website/public/] strip per-dir prefix: /var/www/html/test1/website/public/index.html -> index.html
[Fri Oct 18 20:30:16.179760 2019] [rewrite:trace3] [pid 17308:tid 140453997967104] mod_rewrite.c(483): [client 10.20.0.40:62131] 10.20.0.40 - - [test1.local/sid#7fbe14d530b8][rid#7fbdf80710a0/subreq] [perdir /var/www/html/test1/website/public/] applying pattern '(.*)' to uri 'index.html'
[Fri Oct 18 20:30:16.179768 2019] [rewrite:trace2] [pid 17308:tid 140453997967104] mod_rewrite.c(483): [client 10.20.0.40:62131] 10.20.0.40 - - [test1.local/sid#7fbe14d530b8][rid#7fbdf80710a0/subreq] [perdir /var/www/html/test1/website/public/] rewrite 'index.html' -> 'http://127.0.0.1:3000/test?q=index.html'
[Fri Oct 18 20:30:16.179771 2019] [rewrite:trace3] [pid 17308:tid 140453997967104] mod_rewrite.c(483): [client 10.20.0.40:62131] 10.20.0.40 - - [test1.local/sid#7fbe14d530b8][rid#7fbdf80710a0/subreq] split uri=http://127.0.0.1:3000/test?q=index.html -> uri=http://127.0.0.1:3000/test, args=q=index.html
[Fri Oct 18 20:30:16.179774 2019] [rewrite:trace2] [pid 17308:tid 140453997967104] mod_rewrite.c(483): [client 10.20.0.40:62131] 10.20.0.40 - - [test1.local/sid#7fbe14d530b8][rid#7fbdf80710a0/subreq] [perdir /var/www/html/test1/website/public/] escaped URI in per-dir context for proxy, http://127.0.0.1:3000/test -> http://127.0.0.1:3000/test
[Fri Oct 18 20:30:16.179777 2019] [rewrite:trace2] [pid 17308:tid 140453997967104] mod_rewrite.c(483): [client 10.20.0.40:62131] 10.20.0.40 - - [test1.local/sid#7fbe14d530b8][rid#7fbdf80710a0/subreq] [perdir /var/www/html/test1/website/public/] forcing proxy-throughput with http://127.0.0.1:3000/test
[Fri Oct 18 20:30:16.179787 2019] [rewrite:trace1] [pid 17308:tid 140453997967104] mod_rewrite.c(483): [client 10.20.0.40:62131] 10.20.0.40 - - [test1.local/sid#7fbe14d530b8][rid#7fbdf80710a0/subreq] [perdir /var/www/html/test1/website/public/] go-ahead with proxy request proxy:http://127.0.0.1:3000/test?q=index.html [OK]
Comment 1 Angelov 2019-10-18 23:25:13 UTC
Also, using the (NS|nosubreq) flag somehow prevents the proxy request from being sent. This happens only when internal sub-requests follow the initial request.

The log shows "go-ahead with proxy request proxy:http://127.0.0.1:3000/test?q= [OK]" but the httpd never issues a request to the proxied application.
Comment 2 Angelov 2019-10-20 12:52:07 UTC
Probably related to https://bz.apache.org/bugzilla/show_bug.cgi?id=56434