Z-blogPHP redirection 301 de deux méthodes différentes implémentées avec le code PHP

一般,服务器和虚拟主机都可以直接设置301 redirection(即301 Saut),不需要额外写代码进行设置。

但是,如果你不想在服务器或虚拟主机上实现301重定向该怎么办呢?

未标题-1.jpg

我们以使用Z-blogPHP程序做的网站为例。

Z-blogPHP程序的网站主题使用的都是统一的头部模板文件header.php

header.php所在路径——根目录/zb_users/theme/主题id/template/

找到header.php文件后,在header.php中添加我们的代码即可!

第一种方式:

实现finchui.com重定向到www.finchui.com

这种方法常常用于新网站。

代码如下:

{php}
if (strpos($_SERVER['HTTP_HOST'], 'www.finchui.com') === false) {
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://www.finchui.com");
    exit();
}
{/php}


第二种方法:

不仅实现finchui.com跳转到www.finchui.com。

还要实现访问例如:finchui.com/zbp-theme/62.html、finchui.com/zbp-theme/重定向到www.finchui.com/zbp-theme/62.html和www.finchui.com/zbp-theme/62.html

En termes simples, le changement ne change que le nom de domaine principal et la partie du suffixe URL restera inchangée.

这种方法常常用于旧的网址已经被搜索引擎收录了许多地址,为了把旧域名的权重转移到新域名,才这么做。

代码如下:


{php}
$redirectHost = 'www.finchui.com;
if (strpos($_SERVER['HTTP_HOST'], $redirectHost) === false) {
    $redirectURL = 'http://' . $redirectHost . $_SERVER['REQUEST_URI'];
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: $redirectURL");
    exit();
}
{/php}

以上的例子中用的是我的网站域名,而我的网站只是做了简单的finchui.com跳转到www.finchui.com,不包含URL后缀。

Pas comme ça.1

Liens dans cet article :https://fr.finchui.com/zblog-course/63.html

Commentaires des internautes

Je suppose que vous aimez

Produits chauds
Articles chauds
Hot Tags
Étiquettes associées
FinchUI Store Edition Zone spéciale de Hong Kong

partage

Copier le lien

Le studio XinglanAjouter des amis

Heures de travail : 9 : 00 - 22 : 00
Samedi et dimanche : 14h00 - 22h00
wechat
Ajouter WeChat au service client