Reputation: 81528
I'm trying to redirect a url to a different url (either 301 or 301). Basically, I'm looking for the go equivalent of following php code:
<?php
// Permanent redirection
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://google.com/");
?>
So far this is what I've done:
writer.Header().Set("Location", "http://google.com")
writer.WriteHeader(301)
And also:
handler := rawHttp.RedirectHandler("http://google.com", 301)
handler.ServeHTTP(writer, req)
It 'kind of' works. The only problem is it write a 'Found' text with a link to http://google.com so I've to click it. I want it to redirect automatically without displaying a 'Found' link.
Upvotes: 2
Views: 620
Reputation: 81528
Solved it. Either works. I was just sending some text before setting up the redirect.
Upvotes: 2