1

This question is related to Apache RewriteMap with URLs containing space doesn't work, but in this case the issue is a space in the value part of the map, not the key part. Say I have this entry:

/a-normal-url/    /a-less-normal url/

As a RewriteMap's txt files are space separated, this won't work as-is. I've thus tried to escape the space:

/a-normal-url/    /a-less-normal%20url/

Unfortunately mod_rewrite will helpfully escape the redirect target, so this will lead to the request being redirected to /a-less-norma%2520url/, which also isn't what I want.

Just in case, I've also used a backslash to escape the space (/a-less-normal\ url/), but unsurprisingly this also didn't help (it will redirect to (/a-less-normal%5c) in that case.

dorian
  • 427
  • 1
  • 8
  • 24

1 Answers1

1

I've actually realized what the answer was when writing the question (classic case of rubber duck debugging).

Just add the NE flag in the RewriteRule that actually uses the rewrite map's output, somewhere along these lines:

# Define the RewriteMap
RewriteMap redirect_map "txt:redirect_map.txt"

# Look up the requested URI in the redirect map. If the result is not empty...
RewriteCond ${redirect_map:%{REQUEST_URI}} ^(.+)$

# ...then use the mapped value for the redirect, without percent-encoding it
RewriteRule . %1  [R=301,L,NE]
dorian
  • 427
  • 1
  • 8
  • 24