小编Mar*_*ton的帖子

从简单 HTTP 服务器中的每个文件中删除 .html 扩展名

我想让当有人访问我的 Go HTTP 服务器上的页面时,他们不会看到.html扩展。例如,当他们访问时,https://example.org/test他们会看到https://example.org/test.html.

我的代码:

package main

import (
    "net/http"
)

func main() {
    fs := http.FileServer(http.Dir("public/"))

    http.Handle("/", http.StripPrefix("/", fs))
    http.ListenAndServe(":8000", nil)
}
Run Code Online (Sandbox Code Playgroud)

http go server

3
推荐指数
1
解决办法
838
查看次数

标签 统计

go ×1

http ×1

server ×1