https://issues.apache.org/bugzilla/show_bug.cgi?id=48499

           Summary: mod_rewrite can't redirect to files with ? in them
           Product: Apache httpd-2
           Version: 2.2.14
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: mod_rewrite
        AssignedTo: [email protected]
        ReportedBy: [email protected]


Hello.

I have a directory /foo that's mapped into my web root by 'Alias /bar /foo'.
/foo contains a file named x?y. I want this file to be reachable by /bar/x%3Fy
and /bar/x?y. So I thought I'd use mod_rewrite.

mod_rewrite makes this unnecessarily hard by its special handling of query
parameters, but I think something like

RewriteCond %{QUERY_STRING} .
RewriteRule ^(/bar/.*)$ $1\%3F%{QUERY_STRING}? [PT]

ought to work. However, this creates only 404s. I can understand that without
[PT] it tries to prepend the web root path, but with [PT] it should arrive at
my alias. This doesn't seem to work, however. I can see the rewrite happening
in the logs, but the resulting url can't be resolved.

I think the above is bug #1.

My next attempt was to bypass the alias and rewrite to the actual file path:

RewriteCond %{QUERY_STRING} .
RewriteRule ^/bar/(.*)$ /foo/$1?%{QUERY_STRING}

This fails because mod_rewrite strips the part after ?, treating it as another
query parameter list. Then I tried /foo/$1\%3F%{QUERY_STRING}?, but that also
404s, maybe because it looks for a file called 'x%3Fy', not 'x?y'.

In any case I couldn't get that to work either, which I think is bug #2.

I eventually found a workaround, using an external redirect:

RewriteCond %{QUERY_STRING} .
RewriteRule ^(/bar/.*)$ $1\%3F%{QUERY_STRING}? [NE,L,R=permanent]

This causes another roundtrip to the client, but it works. But there really
should be a way to do all of this internally. If such a way exists, I didn't
find it, and it's a documentation bug. If such a way doesn't exist, it's a code
bug (and probably a documentation bug as well, because [PT] really looks like
it should do what I want).

Thanks for your attention.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to