R
R
recloudor2016-08-09 07:18:12
go
recloudor, 2016-08-09 07:18:12

go. Why does it redirect to "/"?

If a redirect response arrives on a request to a specific url, then this redirect will now always be returned when this url is accessed.
Even if you restart the program, nothing will change.
It doesn't even get to the handler.
The redirect response is tied to the current browser session.
In a new incognito window, this url will work until redirected.
There is no middleware, gin, but even without it, the same shnyag.
If I change a certain cookie, then I can log in again.
What could be the problem?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Oleg Shevelev, 2016-08-09
@recloudor

https://en.wikipedia.org/wiki/List_of_status_codes...
If in stealth, then the difference is only in the nuances.
I did this for myself:

package tmpl

import (
    "net/http"
)

func Redirect(w http.ResponseWriter, address string) {
    if address == "" {
        address = "/"
    }
    w.Header().Set("Location", address)
    w.Header().Set("Cache-Control", "private, no-store, max-age=0, must-revalidate")
    w.WriteHeader(303)                                                                      // see https://ru.wikipedia.org/wiki/Список_кодов_состояния_HTTP#303
}

A
Alexander Pavlyuk, 2016-08-09
@pav5000

It depends on which redirect code you are using.
301 Moved Permanently - this is a permanent redirect, the browser will cache it and will constantly use it, apparently, you are using it.
302 Found is a temporary redirect for one-time redirects. Try to use it.

G
geebv, 2016-08-09
@geebv

For a more complete understanding of the issue, please provide the code of your program.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question