PHP Implementation 301 redirects and informs the search engine Code _php tutorial

Source: Internet
Author: User
Now the search engine is very selective shaving especially Baidu, if your website or blog is not very famous, then he search your Web page when you have to compare to see if there is the same content, if he does not included. So for small sites or personal blogs if the domain name changes then you need to notify the search engine, so that the search engine can be adjusted and replaced.

Take my practice as an example: the original member of the article is stored in http://bkjia.com/blog/member/this directory. This member is the member's name, so there are 100 members there are 100 such directories. Now the level two domain name has been opened, all the links in the station has become the new level two domain name http://member.bkjia.com/this form. Similarly, member is also a user name for different members. I need to do when how to inform the search engine, so that the search engine in the original link to open a two-level domain name after the link, the advantage is that the search engine will not be because of your new domain under the article and the old link under the article has the same, and give up your new domain under the article included.


Perform 301 redirects

$member = "Member";
$hywzdizhi = "http://". $member. " bkjia.com/";
$uri =$_server[\ ' request_uri\ '];
$amember = "blog/$member/";
if (Stristr ($uri, "$amember")) {
$pieces = Explode ("$amember", $uri);
$wangzhi = "$pieces [1]";
$tiaozhuan = $hywzdizhi. $wangzhi;

Header ("http/1.1 301 Moved permanently");
Header ("Location: $httptiaozhuan");

}

?>

The above command can be implemented when the address is accessed as the original http://bkjia.com/blog/member/and all pages in this linked directory.

Not only automatically jump to the most enabled two-level domain name http://member.bkjia.com/, but also notify the search engine, the original link to a new bar, the original I do not, this is the 301 redirection of the responsibility.

Simply say the principle of the above code. First, use $_server[\ ' request_uri\ '] to take the domain name after the URL, if the URL contains blog/$member/Then the URL is split, take the following link to the prepared http://". $member." bkjia.com/This level two domain name. Second, send 301 redirect command, redirect the URL is the beginning of the two-level domain name combination of the URL. The above command is simple and useless, hoping to help you.

http://www.bkjia.com/PHPjc/364566.html www.bkjia.com true http://www.bkjia.com/PHPjc/364566.html techarticle now the search engine is very selective to shave especially Baidu, if your website or blog is not very famous, then he searches your webpage when must compare to see has the same content, if ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.