javascript - 是否可以使用 javascript 或 jQuery 进行 301 重定向?

标签 javascript jquery seo http-status-code-301

我正在运行 Apache 2.0,我只是想知道是否可以使用 JavaScript 或 jQuery 进行 301 重定向。

我有一个 <a></a>href 标记到指定位置,当我点击该链接时,系统会要求我进行 301 重定向。

这是针对 SEO 的,我正在尝试找到一种方法来将 301 重定向到链接中的同一页面,而无需创建新页面或创建表单/提交。

最佳答案

我知道这是一个老问题,但答案并没有真正解决问题中提出的主要问题,即用于 SEO 目的的 301 重定向(今天的答案可能与最初提出并回答了问题)。

“不,您不能从客户端进行 301 重定向”的答案在技术上是正确的,但是(更重要的是)您不一定需要这样做。虽然真正的 301 是首选,但在这种不可能的情况下(或者例如从 hashbang URL 转换回传统 URL),问题实际上是是否有实现目标的可行替代方案。

Search Engine Land did a detailed test Google 在 JavaScript 方面的能力,这是该文章的相关摘录:

  1. JavaScript Redirects

We first tested common JavaScript redirects, varying how the URL was represented in different ways. The method we chose was the window.location function. Two tests were performed: Test A included the absolute URL attributed in the window.location function. Test B used a relative URL.

Result: The redirects were quickly followed by Google. From an indexing standpoint, they were interpreted as 301s — the end-state URLs replaced the redirected URLs in Google’s index.

In a subsequent test, we utilized an authoritative page and implemented a JavaScript redirect to a new page on the site with exactly the same content. The original URL ranked on the first page of Google for popular queries.

Result: As expected, the redirect was followed by Google and the original page dropped from the index. The new URL was indexed and immediately ranked in the same position for the same queries. This surprised us, and seems to indicate that JavaScript redirects can (at times) behave exactly like permanent 301 redirects from a ranking standpoint.

The next time your client wants to implement JavaScript redirects for their site move, your answer might not need to be, “please don’t.” It appears there is a transfer of ranking signals in this relationship. Supporting this finding is a quote from Google’s guidelines:

"Using JavaScript to redirect users can be a legitimate practice. For example, if you redirect users to an internal page once they’re logged in, you can use JavaScript to do so. When examining JavaScript or other redirect methods to ensure your site adheres to our guidelines, consider the intent. Keep in mind that 301 redirects are best when moving your site, but you could use a JavaScript redirect for this purpose if you don’t have access to your website’s server."

关于javascript - 是否可以使用 javascript 或 jQuery 进行 301 重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13846738/

相关文章:

html - 对实例开放图协议(protocol)的理解

seo - 将 URL 关键字存储在数据库中,或导出

javascript - 在 Javascript 中对输入字段进行分组

javascript - 添加两个列表进行选择,默认选择第一个

JavaScript 恶意软件。如何研究加密函数?

javascript - 循环遍历 Javascript 表单中的可见输入元素?

javascript - 如何在 Squarespace 中重定向 href 链接?

redirect - 如何设置域名以重定向到另一个 URL,然后检查来自该域的引荐来源网址?

javascript - 如何执行这个数组(jQuery Ajax)?

javascript - 如何将移动的图像细节作为警报