We want Apache HTTPD to redirect all traffic from /
to /cx
.
RedirectMatch 301 ^/$ "/cx"
We expect it to return the following header with a 301 response:
Location: /cx
Instead it returns:
Location: http://internalhostname/cx
Where http://internalhostname
is whatever the incoming Host:
request header contains.
We do not want this as our server is behind a reverse proxy and the client outside cannot handle http://internalhostname
. This internalhostname
is of course added to the request by the reverse proxy but that is as it should be.
Why is httpd adding the full hostname and how can we stop it?
Using UseCanonicalName Off
or UseCanonicalName On
makes no difference: the hostname is always added but with On
it uses the ServerName
.
2
Answers
We've solved this by rewriting the Location header to remove prototcol, hostname and port:
Try replacing your
RedirectMatch
directive with: