重定向时发送状态码重要吗?
Is sending a status code while redirecting important?
我工作的公司有一个带有 .com
顶级域名的主站点,但也拥有多个其他顶级域名,如 .de
和 .es
。这些其他顶级域名将始终使用下面的代码进行重定向。我应该在重定向中添加一个 301 Moved Permanently
状态代码,还是在这种情况下这些状态代码不重要?或者状态码 204 No Content
更合适?
PHP 重定向代码:
<?php
header("Location: https://www.google.com");
exit();
?>
您正在进行永久重定向,因此您应该使用 301 永久移动状态代码。下面的 link 解释了代码及其重要性:
A 301 HTTP header is used when the requested URL permanently moved to a new location. As you are working on your site, you will often use this, because you regularly need to make a 301 redirect to direct an old URL to a new one. If you don’t, users will see a 404 error page if they try to open the old URL and that’s not something you want. Using a 301 will make sure that the link value of the old URL transfers to the new URL.
我工作的公司有一个带有 .com
顶级域名的主站点,但也拥有多个其他顶级域名,如 .de
和 .es
。这些其他顶级域名将始终使用下面的代码进行重定向。我应该在重定向中添加一个 301 Moved Permanently
状态代码,还是在这种情况下这些状态代码不重要?或者状态码 204 No Content
更合适?
PHP 重定向代码:
<?php
header("Location: https://www.google.com");
exit();
?>
您正在进行永久重定向,因此您应该使用 301 永久移动状态代码。下面的 link 解释了代码及其重要性:
A 301 HTTP header is used when the requested URL permanently moved to a new location. As you are working on your site, you will often use this, because you regularly need to make a 301 redirect to direct an old URL to a new one. If you don’t, users will see a 404 error page if they try to open the old URL and that’s not something you want. Using a 301 will make sure that the link value of the old URL transfers to the new URL.