PHP页面重定向

PHP 页面重定向到 URL。PHP 301 重定向。

此 PHP 重定向应返回 HTTP 响应状态代码:301 Moved Permanently。

搜索引擎使用 301 响应状态代码将页面排名从旧 URL 转移到新 URL。

PHP 标头重定向

将 old-page.php 代码替换为 new-page.php 的重定向代码。

旧页面.php:

<?php
// PHP 永久 URL 重定向
header("Location: http://www.domain.com/new-page.php", true, 301);
exit();
?>

旧页面必须具有 .php 文件扩展名。

新页面可以带有任何扩展名。

PHP 重定向示例

示例#1

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 重定向测试 - PHP 文件

示例#2

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 重定向通常不起作用,除非它在 .htaccesshttpd.conf文件中启用

 

PHP 重定向测试 - HTML 文件

 

要在 HTML 文件中启用 PHP,请将此代码添加到.htaccesshttpd.conf文件中:

添加类型应用程序/x-httpd-php .htm .html

 

我要留言

    热门工具

 

    联系我们