Redirecciones 301 de dos métodos diferentes implementados por Z-blogPHP con código PHP

En general, tanto el servidor como el host virtual se pueden configurar directamente.301 Redirección(即301 Salto),不需要额外写代码进行设置。

但是,如果你不想在服务器或虚拟主机上实现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

简单说,改方式只改变主域名,URL 后缀部分仍将保持不变。

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

代码如下:


{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后缀。

No me gusta1

Enlace para este artículo:https://es.finchui.com/zblog-course/63.html

网友评论

Supongo que te gusta

Mercancías populares
Artículo popular
Etiquetas populares
Etiquetas relacionadas
FinchUI Store versión Zona Especial Especial de Hong Kong

Compartir

Copiar el link

Estudio Lan XingAñadir amigos

Horario de trabajo: 9: 00 - 22: 00
Sábado y domingo: 14: 00 - 22: 00
wechat
Escaneo de código para agregar servicio al cliente WeChat