Website optimization to avoid redirects (301/302)

Source: Internet
Author: User

Redirects increase the number of HTTP requests that affect the performance of the entire site, but the necessary redirects can improve the user experience, so we need to weigh the performance and the user experience, Achieve the best goal: The following is the PHP implementation of 301 permanent redirection and 302 temporary redirection and how to avoid redirection:

First, for many sites, take the site domain name baidu.com as an example: the user in the browser input URL http://www.baidu.com/ or http://www.baidu.com/index.php , in fact, access to the site is the home page; users enter the Web address in the browser http://www.baidu.com/ or http://baidu.com/ , access to the site is still the home page.

In addition, in some cases, we may need to move a file in the site to a new location or change the name of the file. At this point, the user may still enter a previously favorite URL to access the Web page file, so we need to try to ensure that the previous URL and new URLs have access to the latest Web content.

However, for the search engine, two different paths of URLs, and no other special description, it will be the search engine is considered to be two separate pages, so as to be included separately. However, because the content of two pages is the same, the search engine may reduce the rights of the above URLs to deal with, thus affecting the effect of SEO.

In order to avoid adverse effects on SEO and to give users a good experience, we should use special instructions to tell search engines that they are actually the same page. Of course, not only for the SEO, for a good site, each page should also correspond to a unique URL.

Here, we need to use "special instructions" to tell the browser or search engine, "the old URL and the new URL is actually the same page, it is recommended that the browser or search engine use the new URL to access the page", "special Instructions" here is HTTP redirection. HTTP redirection, in short, is when a user's browser or search engine accesses an old URL, the server tells the browser or search engine, "the page has moved, the address of the new home is ..., please use the new address to access the page". For example, when a user accesses a URL http://www.baidu.com/index.php , the server tells the browser that the page should be redirected to http://www.baidu.com/ . At this point, the browser or search engine will automatically jump to the new URL to access the content of the page.

HTTP redirection is also classified as permanent redirection (HTTP status Code 301) and temporary redirection (HTTP status code is 302). Permanent redirection means that the site has moved to a permanently populated "new home", and temporary redirection means that the site has been relocated to a temporary residence "apartment". Below, we use PHP to implement 302 temporary redirects and 301 permanent redirects, respectively.

Second, how to avoid redirection:

1, when defining the href attribute of the link address, try to use the most complete, direct address. For example

Use www.cnblogs.com instead of cnblogs.com
Use cn.bing.com instead of bing.com
Use www.google.com.hk instead of google.com
Use www.mysite.com/products/instead of www.mysite.com/products
2, when using Response.Redirect, set the second parameter to False

Consider whether Server.Execute can be used instead of
Consider Respone.redirectpermanent
3. If you are involved in migration from a test environment to a production environment, it is recommended that you define aliases by using the CNAME mechanism in DNS instead of forcing redirection to implement

Website optimization to avoid redirects (301/302)

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.