Home > Backend Development > PHP Tutorial > PHP Tutorial: How to Implement 301 Redirect_PHP Tutorial

PHP Tutorial: How to Implement 301 Redirect_PHP Tutorial

WBOY
Release: 2016-07-22 09:02:48
Original
777 people have browsed it

What is 301 redirect? 301 redirection means that when your website address changes, such as changing domain names, website revisions, etc., and you want visitors or search engines to jump to the new address to visit the website, then you need to do 301 redirection. There are many ways to implement 301 redirection. This article mainly introduces how to implement 301 redirection in PHP programs.

Implement 301 redirect PHP code


$the_host = $_SERVER['HTTP_HOST']; //Mark to get the current domain name

$request_url = isset($_SERVER['REQUEST_URI'])?$_SERVER['REQUEST_URI']:''; //Determine the last part of the address

If($the_host !== ‘www.bkjia.com’) //There is no changed domain name address

{ header('HTTP/1.1 301 Moved Permanently'); // Prompt to issue 301

header('Location: http://www.bkjia.com/'.$request_url); //Add a new domain name address

}

?>

In which file to add the 301 redirect command

Add 301 redirect instructions to the .htaccess file and use "mod_rewrite" technology.

Example:

RewriteEngine on

RewriteRule ^(.*)$ http://www.bkjia.com/$1 [R=301,L]

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/371840.htmlTechArticle What is a 301 redirect? 301 redirect is when your website address changes, such as changing domain names, website revisions, etc., you want visitors or search engines to jump to the new address to visit...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template