# Redirect

Redirect merupakan pemindahan resource dari suatu alamat URL ke alamat baru. Untuk http status yang digunakan pada redirect bisa berupa:

* http.StatusMovedPermanently(301) -> resource yang di request telah dipindahkan ke url yang baru.
* http.StatusTemporaryRedirect(307) -> resource untuk sementara dipindahkan ke url lain.
* http.StatusPermanentRedirect(308) -> resource telah dipindahkan permanen ke url lain.

```go
package main

import (
	"fmt"
	"net/http"
)

func main() {
	mux := http.NewServeMux()
	mux.HandleFunc("/welcome", func(w http.ResponseWriter, r *http.Request) {
		http.Redirect(w, r, "https://www.google.com", http.StatusMovedPermanently)
	})

	server := http.Server{
		Addr: 	"localhost:5000",
		Handler: mux,
	}

	fmt.Println("Server running on", server.Addr)
	err := server.ListenAndServe()
	if err != nil {
		panic(err)
	}
}

```

<figure><img src="https://1578455751-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F09pucuEBc5BTaaur3uoo%2Fuploads%2FrkvBFoZgdWeF3cMT6Z2d%2Fredirect.png?alt=media&#x26;token=27828109-6f7d-449a-a2cc-77a59be8e96a" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rafli-ramadhan.gitbook.io/golang-example-code-by-topic/go-native-http/redirect.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
