Redirecionamento 301 de dois métodos diferentes implementados usando código PHP

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

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

Sem título - 1.jpg

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

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

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

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

第一种方式:

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

Este método é frequentemente usado para novos sites.

O código é o seguinte:

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

Também implementar acesso, por exemplo: finchui.com/zbp-theme/62.html, finchui.com/zbp-theme/ redirecionar para www.finchui.com/zbp-theme/62.html e www.finchui.com/zbp-theme/62.html.

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

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

O código é o seguinte:


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

Não gosto.1

Link para este artigo:https://pt.finchui.com/zblog-course/63.html

Comentários dos internautas

Eu acho que você gosta.

Mercadorias populares
Artigos populares
Rótulos quentes
Rótulos relevantes
Edição da FinchUI Store Região Especial Preferencial de Hong Kong

Compartilhamento

Copia do link

Estúdio Lan XingAdicione um amigo

Horário de trabalho: 9: 00 - 22: 00
Sábado, domingo: 14: 00 - 22: 00
wechat
Digitalizar código para adicionar WeChat de atendimento ao cliente