title: Golang Gorilla mux with http.FileServer returning 404
body: <p>The problem I'm seeing is that I'm trying to use the <code>http.FileServer</code> with the Gorilla mux Router.Handle function.</p>
  
  <p>This doesn't work (the image returns a 404)..</p>
  
  <pre><code>myRouter := mux.NewRouter()
  myRouter.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir(HomeFolder + "images/"))))
  </code></pre>
  
  <p>this works (the image is shown ok)..</p>
  
  <pre><code>http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir(HomeFolder + "images/"))))
  </code></pre>
  
  <p>Simple go web server program below, showing the problem...</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "net/http"
      "io"
      "log"
      "github.com/gorilla/mux"
  )
  
  const (
      HomeFolder = "/root/test/"
  )
  
  func HomeHandler(w http.ResponseWriter, req *http.Request) {
      io.WriteString(w, htmlContents)
  }
  
  func main() {
  
      myRouter := mux.NewRouter()
      myRouter.HandleFunc("/", HomeHandler)
      //
      // The next line, the image route handler results in 
      // the test.png image returning a 404.
      // myRouter.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir(HomeFolder + "images/"))))
      //
      myRouter.Host("mydomain.com")
      http.Handle("/", myRouter)
  
      // This method of setting the image route handler works fine.
      // test.png is shown ok.
      http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir(HomeFolder + "images/"))))
  
      // HTTP - port 80
      err := http.ListenAndServe(":80", nil)
  
      if err != nil {
          log.Fatal("ListenAndServe: ", err)
          fmt.Printf("ListenAndServe:%s\n", err.Error())
      }
  }
  
  const htmlContents = `&lt;!DOCTYPE HTML&gt;
  &lt;html lang="en"&gt;
    &lt;head&gt;
      &lt;title&gt;Test page&lt;/title&gt;
      &lt;meta charset = "UTF-8" /&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;p align="center"&gt;
          &lt;img src="/images/test.png" height="640" width="480"&gt;
      &lt;/p&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  `
  </code></pre>