What is a 301 redirect? 301 redirect is when your site address changes, such as changing the domain name, website revision, etc., you want visitors or search engines to jump to a new address to visit the site, then you need to do 301 redirect. There are many ways to achieve 301 redirects, this article mainly describes how to achieve 301 redirect PHP program.
implement 301 redirect PHP code
<?php
$the _h ost = $_server[' Http_host ']; //Mark gets the current domain name
$request _url = isset ($_server[' Request_uri '])? $_server[' Request_uri ']: '; //The following section of the address
if ($the _host!== ' www.3lian.com ") & nbsp;//has not replaced the domain name address
{header (' http/1.1 moved Permanently '); //prompt to issue a \
&NBSP ; Header (' Location: http://www.3lian.com/ '. $request _url); //Add a new domain name address
}
?
Add 301 redirect instructions in which file
Adds 301 redirect instructions to the. htaccess file, using “mod_rewrite” technology.
Example:
Rewriteengine on
Rewriterule ^ (. *) $ http://www.3lian.com /$1 [r=301,l]