This article to introduce the PHP implementation of 301 permanent redirection will not take the WWW domain name to the domain name with WWW, the implementation method is obtained.
When your site domain name changes or Web address changes (changes in the directory or the name of the Web page change), how to ensure that the site during the transition period from the search engine traffic will not be lost, and can update the search engine results in the page address? 301 redirects are an ideal way to solve this problem by directing users and search engines to the right page
The code is as follows |
Copy Code |
$the _host = $_server[' http_host '];//get into the domain name entered $request _url = isset ($_server[' Request_uri ') "$_server[' Request_uri ']:";//Determine the back part of the address if ($the _host!== ' www.bKjia.c0m ')//This is where I want the previous domain address {Header (' http/1.1 301 Moved permanently ');//301 head issued Header (' location:http://www.bkjia.c0m '. $request _url);//jump to my new domain address } ?> |
1. Add 301 redirect instructions in the. htaccess file
Using the "mod_rewrite" technique, the shape is as follows:
The code is as follows |
Copy Code |
Rewriteengine on Rewriterule ^ (. *) $ http://www.bkjia.c0m/$1 [r=301,l] |
http://www.bkjia.com/PHPjc/629013.html www.bkjia.com true http://www.bkjia.com/PHPjc/629013.html techarticle This article to introduce the PHP implementation of 301 permanent redirection will not take the WWW domain name to the domain name with WWW, the implementation method is obtained. When your site domain name changes or the Web address changes (Web page ...