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