Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Redirect 自动301在Go中重定向_Redirect_Go - Fatal编程技术网

Redirect 自动301在Go中重定向

Redirect 自动301在Go中重定向,redirect,go,Redirect,Go,我正在尝试将url重定向到其他url(301或301)。基本上,我正在寻找以下php代码的go等价物: <?php // Permanent redirection header("HTTP/1.1 301 Moved Permanently"); header("Location: http://google.com/"); ?> 而且: handler := rawHttp.RedirectHandler("http://google.com", 301) handler.Se

我正在尝试将url重定向到其他url(301或301)。基本上,我正在寻找以下php代码的go等价物:

<?php
// Permanent redirection
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://google.com/");
?>
而且:

handler := rawHttp.RedirectHandler("http://google.com", 301)
handler.ServeHTTP(writer, req)

它“有点”管用。唯一的问题是它写了一个“找到”的文本和一个链接,所以我必须点击它。我希望它自动重定向,而不显示“已找到”链接。

解决了这个问题。两种方法都有效。在设置重定向之前,我刚刚发送了一些文本。

解决了这个问题。两种方法都有效。我只是在设置重定向之前发送了一些文本

handler := rawHttp.RedirectHandler("http://google.com", 301)
handler.ServeHTTP(writer, req)