0

I have a simple go server listening on :8888.

package main

import (
  "log"
  "net/http"
)

func main() {

  http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    log.Println("redirecting to foo")
    http.Redirect(w, r, "foo", http.StatusFound)
  })

  http.HandleFunc("/foo", func(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("fooooo"))
  })

  if err := http.ListenAndServe(":8888", nil); err != nil {
    log.Fatal(err)
  }
}

I have this sitting behind apache which proxies all requests to /bar/* to the go server. I'm using ProxyPassMatch to do this.

 ProxyPassMatch ^/bar/?(:?(.*))?$ http://localhost:8888/$2

Problem is that is what when I go to /bar/ I get redirected to /foo instead of /bar/foo

Is there a way to get this working or do I need to prefix all my redirects with /bar?

Ilia Choly
  • 18,070
  • 14
  • 92
  • 160

1 Answers1

1

If you want Apache to rewrite locations in redirect responses, you'll need to also include the ProxyPassReverse directive in your configuration. Something like this should do the trick:

ProxyPassReverse /bar/ http://localhost:8888/
James Henstridge
  • 42,244
  • 6
  • 132
  • 114
  • I added the `ProxyPassReverse` directive after `ProxyPassMatch` and it did not make a difference. I checked the logs but couldn't find anything useful. Suggestions? – Ilia Choly Jan 21 '14 at 14:24