如何在不使用 JavaScript 的情况下最好地重定向网页?
我的默认页面中有一些脚本,可以根据浏览器的语言将用户重定向到我网站的特定语言版本。 我想添加一些内容来重定向那些未启用 Javascript 的用户。
目前我有以下内容:
<noscript>
<META HTTP-EQUIV=REFRESH CONTENT="1; URL=en/index.htm">.
</noscript>
但我读过这不太明智,因为一些搜索引擎对此不以为然。 我该如何做到这一点并让搜索引擎满意?
I have some script in my default page that redirects users to language specific versions of my website depending on the language of the browser. I want to add something that redirects those users who do NOT have Javascript enabled.
Currently I have the following :
<noscript>
<META HTTP-EQUIV=REFRESH CONTENT="1; URL=en/index.htm">.
</noscript>
But I've read this is not too wise as some search engines frown upon it. How do I do this and keep search engines happy?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您应该使用 .htaccess 文件从标头中检测浏览器的语言(使用正则表达式),然后以这种方式重定向它们。 这样做与客户端配置完全无关,搜索引擎将正确处理它。 有大量关于具体如何实现这一目标的信息。
You should use a .htaccess file to detect the browser's language from the headers (using a regular expression) and then redirect them that way. Doing that is completely agnostic of the client-side configuration and search engines will handle it properly. There is a ton of information out there on specifically how to accomplish this.
可以使用服务器端语言来完成,添加以下 http 标头
将用户重定向到 http:// www.example.com/en/index
It could be done with a server side language by adding the following http header
will redirect the user to http://www.example.com/en/index
您需要解析
Accept-Language
HTTP标题。You'll need to parse the
Accept-Language
HTTP header.您也可以在服务器端使用 301 HTTP 状态代码进行重定向。 这是实现良好 SEO 的最佳方法。 该示例是用 C# 编写的,但每个平台都有自己的方法来向响应添加标头:
使用 301 状态代码的原因是搜索引擎索引新页面,因为它是“永久移动”而不是“已永久移动”的 302。暂时搬家了”。
You can redirect at server side with 301 HTTP status code too. This is the best way to do it for good SEO. The example is in C# but every plattform has his own method to add headers to the response:
The reason to use the 301 status code is that the search engine indexes the new page because it was "Moved permanently" instead of the 302 that was "Moved temporarily".
为什么不通过使用 302 HTTP 状态代码进行响应来在服务器端进行重定向。 我不知道你的服务器上有什么,但所有框架都支持它。
Why don't you redirect on the server side, by responding with a 302 HTTP status code. I don't know what you have on the server, but all frameworks support it.