我们可以使用 javascript 进行 302 重定向吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7658199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can we do 302 redirect with javascript?
提问by user4951
Or does it have to be server side?
还是必须是服务器端?
Currently google requires all sites to 302 to a page rather than the usual pages.
目前 google 要求所有网站都 302 到一个页面,而不是通常的页面。
How do I do so with javascript? Can I just print a 302 code in meta or something?
我如何使用 javascript 执行此操作?我可以只在元数据或其他东西中打印 302 代码吗?
Note: sorry. This is not google for search engine. This is google the feed provider for bodis.com above.com namedrive.com and a bunch of other guy.
注:对不起。这不是谷歌搜索引擎。这是 google bodis.com above.com namedrive.com 和其他一些人的提要提供者。
I am a domain parker. I get domains ranked at search engine and move traffic somewhere else. The problem is google now prohibit URL forwarding. I am just thinking how do I maintain my ranking with more transparent forwarding such as 302. The destination URL is pretty, I would say blank.
我是域名停放者。我让域名在搜索引擎上排名并将流量转移到其他地方。问题是谷歌现在禁止 URL 转发。我只是在想如何通过更透明的转发(例如 302)来保持我的排名。目标 URL 很漂亮,我会说空白。
回答by Dennis
This is how a 302 redirect works:
这是 302 重定向的工作原理:
HTTP 302
means found. In a way, the server tells the client where to retrieve the page it requested.
HTTP 302
意味着找到。在某种程度上,服务器告诉客户端从哪里检索它请求的页面。
Example:
例子:
The client sends:
客户端发送:
GET /index.html HTTP/1.1
Host: www.yourdomain.com
The server responds:
服务器响应:
HTTP/1.1 302 Found
Location: http:/yoursubdomain.someotherdomain.com/somefolder
This is why you couldn't achieve a 302 redirect using javascript. It's part of the HTTP protocol. No page gets loaded by the client's browser before the redirect is performed.
这就是您无法使用 javascript 实现 302 重定向的原因。它是 HTTP 协议的一部分。在执行重定向之前,客户端的浏览器不会加载任何页面。