title: Second FileServer serves html but not images
body: <p>I'm running into the following problem with Go and <code>gorilla/mux</code> routers when building a simple API. I'm sure it's the usual stupid mistake that is right on my face, but I can't see it.</p>
  
  <h3>Simplified project structure</h3>
  
  <pre><code>|--main.go
  |
  |--public/--index.html
  |        |--image.png
  |
  |--img/--img1.jpg
  |     |--img2.jpg
  |     |--...
  |...
  </code></pre>
  
  <h3><code>main.go</code></h3>
  
  <pre class="lang-golang prettyprint-override"><code>package main
  
  import (
      "net/http"
      "github.com/gorilla/mux"
  )
  
  var Router = mux.NewRouter()
  
  func InitRouter() {
      customers := Router.PathPrefix("/customers").Subrouter()
  
      customers.HandleFunc("/all", getAllCustomers).Methods("GET")
      customers.HandleFunc("/{customerId}", getCustomer).Methods("GET")
      // ...
      // Registering whatever middleware
      customers.Use(middlewareFunc)
  
      users := Router.PathPrefix("/users").Subrouter()
  
      users.HandleFunc("/register", registerUser).Methods("POST")
      users.HandleFunc("/login", loginUser).Methods("POST")
      // ...
  
      // Static files (customer pictures)
      var dir string
      flag.StringVar(&amp;dir, "images", "./img/", "Directory to serve the images")
      Router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir(dir))))
  
      var publicDir string
      flag.StringVar(&amp;publicDir, "public", "./public/", "Directory to serve the homepage")
      Router.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir(publicDir))))
  }
  
  func main() {
      InitRouter()
      // Other omitted configuration
      server := &amp;http.Server{
          Handler: Router,
          Addr:    ":" + port,
          // Adding timeouts
          WriteTimeout: 15 * time.Second,
          ReadTimeout:  15 * time.Second,
      }
  
      err := server.ListenAndServe()
      // ...
  }
  </code></pre>
  
  <p>Subroutes work OK, with middleware and all. The images under <code>img</code> are correctly served if I go to <code>localhost:5000/static/img1.png</code>.</p>
  
  <p>The thing is, going to <code>localhost:5000</code> serves the <code>index.html</code> that resides in <code>public</code>, but then <code>localhost:5000/image.png</code> is a <code>404 not found</code> instead.</p>
  
  <p>What is happening here?</p>