3

Today I've noticed that mod_alias's Redirect and RedirectMatch directives show a different behavior in how they handle the redirect URL.

A statement like this:

Redirect 301 "/foo" "/bar%20baz"

will redirect to the literal URL bar%20baz, whereas

RedirectMatch "/foo" "bar%20baz"

will redirect to bar%2520baz, as the redirect URL's percent sign is escaped.

My redirect URLs are already escaped. Is there any way I can tell RedirectMatch to not escape them any further?

dorian
  • 397
  • 1
  • 7
  • 22

1 Answers1

1

As far as I understand the manual you would not need to percent encode the new URL anyway and could use:

 Redirect "/foo"  "/bar baz"
 RedirectMatch "regex" "/bar baz"
HBruijn
  • 72,524
  • 21
  • 127
  • 192
  • You are absolutely right and that's what I ended up doing even though it meant unescaping ~1000 redirect URLs. I was just surprised that there's a difference in how `Redirect` and `RedirectMatch` treat the redirect URL. – dorian Jul 12 '16 at 16:15
  • 1
    "as I understand the manual" - the manual does not appear to make any reference to whether the _target_-URL is automatically URL-encoded (%-encoded) or not? In fact, the `Redirect` directive does not appear to URL-encode the target URL before sending the response. Whereas the `RedirectMatch` directive does! Can't see why there should be a difference, considering the manual states that these two directives are "equivalent". `Redirect "/foo" "/bar baz"` (unencoded target URL) only "works" because the **browser** is "fixing" (ie. URL encoding) the URL before making the 2nd request. – MrWhite Dec 08 '16 at 12:07