I'm trying to get around an HTTP 400 Bad Request with Apache that is caused when this URL is accessed (actual domain redacted):
http://example.com/nw/f/RUD/E.enc<space>
The URL ends with an actual space character, thus giving an HTTP 400 Bad Request. I cannot get the clients requesting this to remove the space in the URL, so I need to rewrite the URL without a space.
I've tried some RewriteRules, like this one (after enabling the RewriteEngine):
RewriteRule "^/nw/f/RUD/E(.*)$" /nw/f/RUD/E.enc [P]
The RewriteRule has no effect and is still giving an HTTP 400.
It even happens when I escape the space character instead of using the wildcard in the rule. Same thing if I try to replace the HTTP 400 error page to lead to the actual content (which wouldn't be ideal, since there's 4 different files).
How can I correctly rewrite the URL, removing the space on it, without getting HTTP 400?
Your RewriteRule produces a redirect loop as .../E.enc<space> and .../E.enc both match .../E(.*)$.
Better use a [R]edirect, though proxying also works.
RewriteEngine On
RewriteRule "^/nw/f/RUD/E\.enc $" /nw/f/RUD/E.enc [R,L]
or shorter
RewriteEngine On
RewriteRule "^(/nw/f/RUD/E\.enc) $" $1 [R,L]