generated from ElnuDev/go-project
Redirect /search and /search to /
This commit is contained in:
parent
b6d3b703c9
commit
d18c9303c6
1 changed files with 5 additions and 0 deletions
|
@ -138,6 +138,11 @@ func main() {
|
||||||
func(w http.ResponseWriter, r *http.Request) any { return nil },
|
func(w http.ResponseWriter, r *http.Request) any { return nil },
|
||||||
[]string{http.MethodGet},
|
[]string{http.MethodGet},
|
||||||
))
|
))
|
||||||
|
redirectToHome := func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
http.Redirect(w, r, "/", http.StatusPermanentRedirect)
|
||||||
|
}
|
||||||
|
r.HandleFunc("/search", redirectToHome)
|
||||||
|
r.HandleFunc("/search/", redirectToHome)
|
||||||
r.HandleFunc("/search/{query}", httputils.GenerateHandler(
|
r.HandleFunc("/search/{query}", httputils.GenerateHandler(
|
||||||
"index.html",
|
"index.html",
|
||||||
func(w http.ResponseWriter, r *http.Request) bool {
|
func(w http.ResponseWriter, r *http.Request) bool {
|
||||||
|
|
Reference in a new issue