PHP301跳转代码
确定您想要的是PHP 301跳转代码吗?301跳转通常是用来永久重定向网页到另一个网页,如果是这样的话,您可以使用下面的代码:
<?php
// 请将下面的URL替换为您想要重定向到的网页的URL
$new_url = 'http://www.example.com/new-page';
// 发送301响应头
header('HTTP/1.1 301 Moved Permanently');
// 重定向到新网页
header('Location: '.$new_url);
// 结束脚本
exit; ?>
// 请将下面的URL替换为您想要重定向到的网页的URL
$new_url = 'http://www.example.com/new-page';
// 发送301响应头
header('HTTP/1.1 301 Moved Permanently');
// 重定向到新网页
header('Location: '.$new_url);
// 结束脚本
exit; ?>
请注意,在上面的代码中,您需要替换$new_url
变量的值为您想要重定向到的网页的URL。
另外,请确保在发送响应头之前没有输出任何内容,否则可能会出现问题。如果您在脚本中使用了输出缓冲(output buffering),则需要在发送响应头之前调用ob_end_clean()
函数清空输出缓冲区。
例如:
<?php
// 清空输出缓冲区
ob_end_clean();
// 请将下面的URL替换为您想要重定向到的网页的URL
$new_url = 'http://www.example.com/new-page';
// 发送301响应头
header('HTTP/1.1 301 Moved Permanently');
// 重定向到新网页
header('Location: '.$new_url);
// 结束脚本
exit; ?>
// 清空输出缓冲区
ob_end_clean();
// 请将下面的URL替换为您想要重定向到的网页的URL
$new_url = 'http://www.example.com/new-page';
// 发送301响应头
header('HTTP/1.1 301 Moved Permanently');
// 重定向到新网页
header('Location: '.$new_url);
// 结束脚本
exit; ?>
如果您有其他问题,请随时联系我。
评论