PHP 从页面重定向到 URL。PHP 301 重定向。
此 PHP 重定向应返回 HTTP 响应状态代码:301 永久移动。
搜索引擎使用 301 响应状态代码将页面排名从旧 URL 转移到新 URL。
将 old-page.php 代码替换为指向 new-page.php 的重定向代码。
旧页面.php:
<?php
// PHP permanent URL redirection
header("Location: http://www.domain.com/new-page.php", true,
301);
exit();
?>
旧页面必须有 .php 文件扩展名。
新页面可以使用任何扩展名。
php-redirect-test.php
<?php
// PHP permanent URL redirection test
header("Location:
https://cmtoinchesconvert.com/zh-CN/web/dev/php-redirect.html", true, 301);
exit();
?>
按此链接从 php-redirect-test.php 重定向回此页面:
php-redirect-test.htm
<?php
// PHP permanent URL redirection test
header("Location:
https://cmtoinchesconvert.com/zh-CN/web/dev/php-redirect.html", true, 301);
exit();
?>
由于 .html 文件扩展名,从 html 文件 php-redirect-test.htm 进行的 PHP 重定向通常不起作用,除非它在 .htaccess 或 httpd.conf 文件中启用:
要在 HTML 文件中启用 PHP,请将此代码添加到.htaccess 或 httpd.conf 文件中:
Addtype application/x-httpd-php .htm .html
Advertising