Bug 52831 - mod_rewrite redirect broken with IPv6 literal address
Summary: mod_rewrite redirect broken with IPv6 literal address
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_rewrite (show other bugs)
Version: 2.2.21
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
Keywords: FixedInTrunk, PatchAvailable
Depends on:
Reported: 2012-03-05 18:05 UTC by Diego Santa Cruz
Modified: 2015-05-11 08:55 UTC (History)
1 user (show)

Proposed patch (1.03 KB, patch)
2012-03-05 18:08 UTC, Diego Santa Cruz
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Diego Santa Cruz 2012-03-05 18:05:39 UTC
A redirect written using mod_rewrite is broken when the URL uses a literal IPv6 address, the redirect location is missing the square brackets around the IPv6 address.

To test set the following two rewrite rules

RewriteRule ^/a/                        /A/ [R,L]
RewriteRule ^/c/                        C/ [R,L]

Let's say the server's IPv6 address is fd35:299:14bc:0:21d:50ff:fe00:1a, then with http://[fd35:299:14bc:0:21d:50ff:fe00:1a]/a/ the redirect location is http://fd35:299:14bc:0:21d:50ff:fe00:1a/a/ and similar for /c.

This issue has been fixed with other mod_alias redirects and mod_proxy but it is still present in mod_rewrite as of 2.2.21.
Comment 1 Diego Santa Cruz 2012-03-05 18:08:06 UTC
Created attachment 28421 [details]
Proposed patch

This patch fixed the problem for me, tested with IPv6 and IPv4 literals as well as hostname in original URL, using both defined redirects "/a/" and "c/".
Comment 2 Christophe JAILLET 2015-05-09 14:13:17 UTC
Hi and sorry for the late answer.

This has been fixed in 2.3.5 (now 2.4.x branch) in r900022 a few years ago.
The patch is not exactly the same as the one proposed here, but it does the same thing (i.e. turn 'ap_get_server_name' into 'ap_get_server_name_for_url' where needed)

I've chosen to propose for backport the same version as the one in the 2.4.x branch. (see r1678492)
Comment 3 Diego Santa Cruz 2015-05-11 08:23:13 UTC
I actually saw that this was fixed in 2.3.5 just last Friday while porting our local patches from 2.2.x to 2.4.x :-)

Thanks for proposing to backport to 2.2.x branch.
Comment 4 Yann Ylavic 2015-05-11 08:55:21 UTC
Backport to 2.2.30 accepted, will be in next release.