skip to Main Content

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


  1. Chosen as BEST ANSWER

    We've solved this by rewriting the Location header to remove prototcol, hostname and port:

    RedirectMatch 301 ^/$ "/cx/"
    Header edit Location "(^http[s]?://)([a-zA-Z0-9.-]+)(:d+)?/" "/"
    

  2. Try replacing your RedirectMatch directive with:

    RewriteEngine on
    RewriteRule ^/$ http://%{HTTP_HOST}/cx [NC,R=301]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search