301重定向就是告诉搜索引擎永远都改变了地址了,这个就是跳转了会返回一个301状态码给搜索引擎了,所有搜索引擎都遵守这个规则了。
一、网站初期,一般只需做不带www的域名301转向到带www域名上;
代码如下:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^111cn.net [nc]
rewriterule ^(.*)$ http://www.111cn.net /$1 [r=301,nc]
二、不同域名301跳转方法;
当想重新更换域名时,我们就需要把原有的网站权重移动到最新的网站上,就需要做不同域名的301跳转;
代码如下:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^www.domain1.com [nc]
rewriterule ^(.*)$ http://www.domain2.com/$1 [r=301,nc]
注:此类跳转,一般是因网站改版而起,如果想要把权重最大化转移,请根据百度站长平台给出的解决办法进行解决。
以上2种方法,是针对Apache而言,如果你用得非Apache(如:nginx),那么就不能用.htaccses文件,也就不能使用以上方法,那怎么办?——对网页直接进行301跳转修改!
一、对某个单页面进行301跳转,只需在PHP网页顶部输入下面的代码就可以。代码如下:
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: http://www.111cn.net ");
?>
二、针对全站页面进行301跳转解决方法
1、建立301.php文件
(文件名自取)
$the_host = $_SERVER['HTTP_HOST'];//取得当前域名
$the_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';//判断地址后面部分
$the_url = strtolower($the_url);//将英文字母转成小写
if($the_url=="/index.php")//判断是不是首页
{
$the_url="";//如果是首页,赋值为空
}
{
header('HTTP/1.1 301 Moved Permanently');//发出301头部
header('Location:http://www.111cn.net '.$the_url);//跳转到带www的网址
}
?>
2、在网页文件中调用301.php
将这个代码放到你所有网页的最前面。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor