PHP uses header+location for website 301 Redirection

Source: Internet
Author: User
Tags php website
Article reprinted from PHP using header+location to achieve website 301 Redirect | Lanzhou Fly Rain seo | Http://www.feiyuseo.com/seo-jishu/145.html

For our SEO staff, sometimes need to redirect the site. In general, HTTP return status codes for site redirection are 301 and 3,022. We'll show you how to use Header+location to implement web 301 redirection via PHP using an example.

About the problem of the orientation of the PHP website, in Baidu search above the noon, found that the most used is the use of "header+location" redirection method. Below I give the most popular code:

<? Phpheader ("location:http://www.feiyuseo.com"); exit; >

But through my query to the HTTP status code found that the above code to jump redirected after the return code is 302 state. Let's take a look at what is a 302 return code? The search engine returned a 302 error indicating that the requested resource was temporarily transferred (Moved temporatily), and then a transferred URL was given, and the browser, when processing the 302 error returned by the server, would in principle reestablish a TCP connection and then fetch the redirected URL page But if the page exists in the cache, it is not retrieved. However, due to black hat SEO abuse 302 Redirect to cheat, 302 redirects have been regarded as spam information, by the major search engine hit. Therefore, the above code returns 302 status is not perfect, but also exists by Baidu and other search engine K station risk.

Look at the second method: return the 301 status code before redirecting.

<? Phpheader (' http/1.1 301 Moved permanently '); Header ("location:http://www.feiyuseo.com"); exit; >

This section of the code above can be said to solve the problem of using location to generate 302 State, it is a more complete and relatively safe site redirection method. Just in preparation for the time, I suddenly found a jump code, is also very good, more streamlined than this, here I also attached to everyone, share.

<? Phpheader ("location:http://www.feiyuseo.com", true,301);); exit; >

This line of code on the implementation of the 301 redirection of the site, and efficient, safe, reliable operation.

The above describes PHP using Header+location to achieve site 301 redirection, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.