PHP 和 .htaccess 重定向之间的区别

发布于 2024-08-08 18:59:57 字数 47 浏览 4 评论 0原文

网站 SEO 的 php 标头重定向和 .htaccess 重定向之间有区别吗?

Is there a difference between php header redirect and .htaccess redirect by the SEO of the site?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半寸时光 2024-08-15 18:59:57

可能不会 - 取决于您如何进行重定向。

在 PHP 中:

header("Location: http://www.example.com/"); /* Redirect browser, emits 302 */

如果您想发出 301,请使用:

header("Location: http://www.example.com/", true, 301);

PHP 文档。

如果您在 .htaccess 中执行此操作:

Redirect 302 /PATH_TO_REDIRECT http://www.example.com/

那么也会发出 302。

同样,让它发出 301 很简单:

Redirect 301 /PATH_TO_REDIRECT http://www.example.com/

一般来说,对于 SEO,只需做有意义的事情即可。如果某些内容永久移动,请使用 301,如果某些内容临时移动(例如在临时重新洗牌期间),请使用 302(请查看 响应代码定义)。

Probably not - depends how you're doing your redirection.

In PHP:

header("Location: http://www.example.com/"); /* Redirect browser, emits 302 */

If you want to emit a 301, use:

header("Location: http://www.example.com/", true, 301);

More in the PHP documentation.

If you're doing this in your .htaccess:

Redirect 302 /PATH_TO_REDIRECT http://www.example.com/

then that'll emit a 302 too.

Again, making it emit a 301 is straightforward:

Redirect 301 /PATH_TO_REDIRECT http://www.example.com/

In general, for SEO, just do what makes sense. If something's moved permanently use 301, if something's moved temporarily (e.g. during a temporary reshuffle) use 302 (take a look at the response code definitions).

蓬勃野心 2024-08-15 18:59:57

如果标题相同,我认为根本不重要。

If the header is the same, I don't think it matters at all.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文