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-TW/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-TW/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