PHP implements 301 redirection and notifies the search engine of code _ PHP Tutorial

Source: Internet
Author: User
PHP implements 301 redirection and notifies the search engine code. The current search engine is very simple, especially Baidu. If your website or blog is not very famous, you need to compare it when searching your webpage to see if there is any similar content, if the current search engine is very simple, especially Baidu, if your website or blog is not very famous, then when searching your web page, you should compare it to see if there are any identical content, if there is one, it will not be included. Therefore, if the domain name of a small website or a personal blog changes, you need to notify the search engine so that the search engine can be adjusted and changed.

Take my actual operations as an example: the original articles of a member are stored in the http://bkjia.com/blog/member/directory. This member is the member's name, so there are one hundred members with one hundred such directories. Now that the second-level domain name has been activated, all links in the site have become the newly activated second-level domain name http://member.bkjia.com. Similarly, member is the username of different members. How can I notify the search engine when I need to do so and change the original link in the search engine to the link after the second-level domain name is activated, the advantage is that the search engine does not give up indexing of articles under your new domain name because the articles under your new domain name are similar to those under the old link.


// Perform 301 redirection

$ 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 commands can be implemented when the Accessed address is the original http://bkjia.com/blog/member/ and all the web pages in this link directory.

Not only automatically jump to the most enabled second-level domain name http://member.bkjia.com/, but also notified the search engine, the original link into the new, the original I don't need, this is the 301 redirection rule.

Briefly describe the principles of the above code. 1. use $ _ SERVER [\ 'request _ URI \ '] to retrieve the website address of the domain name. if the website contains blog/$ member/, the website will be split, put the following link in the prepared http ://". $ member. "bkjia.com/under this second-level domain name. 2. send the 301 redirection command. the redirection URL is the URL after the combination starting with the second-level domain name. The above command is very simple and does not use regular expressions at all. I hope it will help you.

...

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.